diff --git a/lib_com/cldfb.c b/lib_com/cldfb.c index db9fd9b27245e69ee26fd16ce9f5a0ce584d5af7..881c473a80c4a02e0c623653573b06a207e25bc0 100644 --- a/lib_com/cldfb.c +++ b/lib_com/cldfb.c @@ -2468,6 +2468,10 @@ void cldfb_restore_memory_ivas_fx( } hs->cldfb_state_length = size; hs->memory_length = 0; +#if 1 //Remove later + free(hs->memory_flt); + hs->memory_flt = NULL; +#endif free( hs->memory32 ); hs->memory32 = NULL; diff --git a/lib_com/float_to_fix_ops.c b/lib_com/float_to_fix_ops.c index 74c2cd642bff3a2cf1225aba0d698eb1de7d9efb..d9079474e18f9733c84ff369b63a88c4921edb7e 100644 --- a/lib_com/float_to_fix_ops.c +++ b/lib_com/float_to_fix_ops.c @@ -76,6 +76,76 @@ void floatToFixed_arr32( float *f, Word32 *i, Word16 Q, Word16 l ) i[j] = float_to_fix( f[j], Q ); } } + +float fixedToFloat_32( Word32 number, Word16 Q ) +{ + float val = 0.0f; + assert( fabs( Q ) <= 63 ); + if ( fabs( Q ) > 31 ) + { + if ( Q > 0 ) + { + val = (float) ( ( number / ( 1 << ( Q - 31 ) ) ) / ( (unsigned int) MAX_32 + 1 ) ); + } + else + { + val = (float) ( number * ( 1 << ( -Q - 31 ) ) * (unsigned int)MIN_32 ); + } + } + else + { + val = fixedToFloat( number, Q ); + } + return val; +} + +Word32 floatToFixed_32( float number, Word16 Q ) +{ + float val = 0.0f; + assert( fabs( Q ) <= 63 ); + if ( fabs( Q ) > 31 ) + { + if ( Q > 0 ) + { + val = ( number * ( (unsigned int) MAX_32 + 1 ) ) * ( 1 << ( Q - 31 ) ); + } + else + { + val = ( number / ( 1 << ( -Q - 31 ) ) ) / (unsigned int)MIN_32; + } + if ( val >= 0.0f ) + { + assert( (Word32) val <= MAX_32 ); + } + else + { + assert( (Word32) val >= MIN_32 ); + } + } + else + { + return floatToFixed( number, Q ); + } + + return (Word32) val; +} + +void floatToFixed_arrL32( float *f, Word32 *i, Word16 Q, Word16 l ) +{ + for ( int j = 0; j < l; j++ ) + { + i[j] = floatToFixed_32( f[j], Q ); + } +} + +void fixedToFloat_arrL32( Word32 *i, float *f, Word16 Q, Word16 l ) +{ + for ( int j = 0; j < l; j++ ) + { + f[j] = fixedToFloat_32( i[j], Q ); + } +} + void floatToFixed_arr(float *f, Word16 *i, Word16 Q, Word16 l) { for (int j = 0; j < l; j++) @@ -205,7 +275,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( delay_comp = 0, Q_loBuffer = 0; Word16 Q_lsf_cng = Q_factor( 6400 ); - Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0, Q_tcxltp_gain_post_prev = 0; + Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0; TD_BWE_DEC_HANDLE hBWE_TD = st->hBWE_TD; Word16 Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_syn_overlap = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0, Q_prev_fb_ener_adjust = 0, Q_fb_state_lpc_syn = 0, Q_genSHBsynth_Hilbert_Mem = 0, Q_genSHBsynth_state_lsyn_filt_shb_local = 0; @@ -300,16 +370,18 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( st->hTcxDec->LastFrameLevel_bfi_fx = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 ); FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) { - st->hTcxDec->NoiseLevelMemory_bfi_fx[i] = (Word16) floatToFixed( st->hTcxDec->NoiseLevelMemory_bfi[i], 15 ); + //f2me_16(st->hTcxDec->NoiseLevelMemory_bfi[i], &st->hTcxDec->conNoiseLevelMemory[i], &st->hTcxDec->conNoiseLevelMemory_e[i]); + //st->hTcxDec->NoiseLevelMemory_bfi_fx[i] = (Word16) floatToFixed( st->hTcxDec->NoiseLevelMemory_bfi[i], 15 ); } st->hTcxDec->cummulative_damping_tcx = (Word16) floatToFixed( st->hTcxDec->cummulative_damping_tcx_float, 15 ); } IF( st->hHQ_core ) { - st->hHQ_core->Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; + //st->hHQ_core->Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; st->hHQ_core->Q_old_out = Q_factor_arr( st->hHQ_core->old_out, L_FRAME48k ); st->hHQ_core->Q_old_outLB = Q_factor_arr( st->hHQ_core->old_outLB, L_FRAME32k ); - floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); + st->hHQ_core->Q_fer_samples = 0; + //floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); floatToFixed_arr( st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->hHQ_core->Q_old_out, L_FRAME48k ); floatToFixed_arr( st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->hHQ_core->Q_old_outLB, L_FRAME32k ); } @@ -347,8 +419,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); - st->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) floatToFixed( st->hTcxLtpDec->tcxltp_gain_post_prev_float, Q_tcxltp_gain_post_prev ); floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_in_float, st->hTcxLtpDec->tcxltp_mem_in, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_out_float, st->hTcxLtpDec->tcxltp_mem_out, Q_tcxltp_mem_out, L_FRAME48k ); } @@ -367,9 +437,9 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, Q_syn_overlap, 20 ); Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); + //Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); - st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); + //st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, Q_fb_state_lpc_syn, 10 ); floatToFixed_arr( hBWE_TD->int_3_over_2_tbemem_dec, hBWE_TD->int_3_over_2_tbemem_dec_fx, Q_int_3_over_2_tbemem_dec, INTERP_3_2_MEM_LEN ); floatToFixed_arr( hBWE_TD->mem_resamp_HB_32k, hBWE_TD->mem_resamp_HB_32k_fx, Q_mem_resamp_HB_32k, 7 ); @@ -420,7 +490,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); + //Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); @@ -434,7 +504,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( fixedToFloat_arr( hBWE_TD->int_3_over_2_tbemem_dec_fx, hBWE_TD->int_3_over_2_tbemem_dec, Q_int_3_over_2_tbemem_dec, 15 ); fixedToFloat_arr( hBWE_TD->mem_resamp_HB_32k_fx, hBWE_TD->mem_resamp_HB_32k, Q_mem_resamp_HB_32k, 7 ); //bool des = ( st->bwidth == WB && st->last_extl != WB_TBE ) || ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ); - st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); + //st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); } st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); IF( st->hTECDec != NULL ) @@ -508,7 +578,8 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( st->hTcxDec->LastFrameLevel_bfi = fixedToFloat( st->hTcxDec->LastFrameLevel_bfi_fx, 15 ); FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) { - st->hTcxDec->NoiseLevelMemory_bfi[i] = fixedToFloat( st->hTcxDec->NoiseLevelMemory_bfi_fx[i], 15 ); + //st->hTcxDec->NoiseLevelMemory_bfi[i] = me2f_16(st->hTcxDec->conNoiseLevelMemory[i], st->hTcxDec->conNoiseLevelMemory_e[i]); + //st->hTcxDec->NoiseLevelMemory_bfi[i] = fixedToFloat( st->hTcxDec->NoiseLevelMemory_bfi_fx[i], 15 ); } st->hTcxDec->cummulative_damping_tcx_float = fixedToFloat( st->hTcxDec->cummulative_damping_tcx, 15 ); } @@ -553,14 +624,12 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( } Q_lsf_cng = Q_factor( 6400 ); - st->past_gpit_float = fixedToFloat( st->past_gpit, 0 ); - st->past_gcode_float = fixedToFloat( st->past_gcode, 0 ); fixedToFloat_arr( st->Aq_cng, st->Aq_cng_float, 2, M ); - if ( st->last_gain_syn_deemph == 16384 ) - { - st->last_gain_syn_deemph_float = 1; - } + //if ( st->last_gain_syn_deemph == 16384 ) + //{ + // st->last_gain_syn_deemph_float = 1; + //} st->last_concealed_gain_syn_deemph_float = fixedToFloat( st->last_concealed_gain_syn_deemph, 14 ); st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 0 ); @@ -572,18 +641,13 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed( } st->old_fpitch_float = fixedToFloat( st->old_fpitch, 16 ); - FOR( i = 0; i < 8; i++ ) - { - st->dispMem[i] = 0; - } + IF( st->hTcxLtpDec != NULL ) { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, Q_tcxltp_mem_out, L_FRAME48k ); - st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, Q_tcxltp_gain_post_prev ); } IF( st->hTonalMDCTConc ) { @@ -648,7 +712,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( Q_pst_old_syn = 0, delay_comp = 0, Q_loBuffer = 0; - Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0, Q_tcxltp_gain_post_prev = 0; + Word16 Q_tcxltp_mem_in = 0, Q_tcxltp_mem_out = 0; TD_BWE_DEC_HANDLE hBWE_TD = st->hBWE_TD; Word16 Q_state_lsyn_filt_shb = 0, Q_state_lsyn_filt_dwn_shb = 0, Q_mem_resamp_HB = 0, Q_syn_overlap = 0, Q_int_3_over_2_tbemem_dec = 0, Q_mem_resamp_HB_32k = 0, Q_prev_fb_ener_adjust = 0, Q_fb_state_lpc_syn = 0, Q_genSHBsynth_Hilbert_Mem = 0, Q_genSHBsynth_state_lsyn_filt_shb_local = 0; @@ -743,16 +807,17 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st->hTcxDec->LastFrameLevel_bfi_fx = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 ); FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) { - st->hTcxDec->NoiseLevelMemory_bfi_fx[i] = (Word16) floatToFixed( st->hTcxDec->NoiseLevelMemory_bfi[i], 15 ); + //f2me_16(st->hTcxDec->NoiseLevelMemory_bfi[i], &st->hTcxDec->conNoiseLevelMemory[i], &st->hTcxDec->conNoiseLevelMemory_e[i]); } st->hTcxDec->cummulative_damping_tcx = (Word16) floatToFixed( st->hTcxDec->cummulative_damping_tcx_float, 15 ); } IF( st->hHQ_core ) { - st->hHQ_core->Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; + //st->hHQ_core->Q_fer_samples = Q_factor_arr( st->hHQ_core->fer_samples + delay_comp, shr( st->hTcxDec->L_frameTCX, 1 ) ) - 1; st->hHQ_core->Q_old_out = 0; st->hHQ_core->Q_old_outLB = 0; - floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); + st->hHQ_core->Q_fer_samples = 0; + //floatToFixed_arr( st->hHQ_core->fer_samples + delay_comp, st->hHQ_core->fer_samples_fx + delay_comp, Q_fer_samples, shr( st->hTcxDec->L_frameTCX, 1 ) ); floatToFixed_arr( st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->hHQ_core->Q_old_out, L_FRAME48k ); floatToFixed_arr( st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->hHQ_core->Q_old_outLB, L_FRAME32k ); } @@ -790,8 +855,6 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); - st->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) floatToFixed( st->hTcxLtpDec->tcxltp_gain_post_prev_float, Q_tcxltp_gain_post_prev ); floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_in_float, st->hTcxLtpDec->tcxltp_mem_in, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); floatToFixed_arr( st->hTcxLtpDec->tcxltp_mem_out_float, st->hTcxLtpDec->tcxltp_mem_out, Q_tcxltp_mem_out, L_FRAME48k ); } @@ -810,9 +873,9 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( floatToFixed_arr( hBWE_TD->syn_overlap, hBWE_TD->syn_overlap_fx, Q_syn_overlap, 20 ); Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); + //Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); - st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); + //st->prev_fb_ener_adjust_fx = (Word16) floatToFixed( st->hBWE_FD->prev_fb_ener_adjust, Q_prev_fb_ener_adjust ); floatToFixed_arr( hBWE_TD->fb_state_lpc_syn, hBWE_TD->fb_state_lpc_syn_fx, Q_fb_state_lpc_syn, 10 ); floatToFixed_arr( hBWE_TD->int_3_over_2_tbemem_dec, hBWE_TD->int_3_over_2_tbemem_dec_fx, Q_int_3_over_2_tbemem_dec, INTERP_3_2_MEM_LEN ); floatToFixed_arr( hBWE_TD->mem_resamp_HB_32k, hBWE_TD->mem_resamp_HB_32k_fx, Q_mem_resamp_HB_32k, 7 ); @@ -864,7 +927,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( Q_syn_overlap = Q_factor_arr( hBWE_TD->syn_overlap, 20 ); Q_int_3_over_2_tbemem_dec = Q_factor_arr( hBWE_TD->int_3_over_2_tbemem_dec, 15 ); Q_mem_resamp_HB_32k = Q_factor_arr( hBWE_TD->mem_resamp_HB_32k, 7 ); - Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); + //Q_prev_fb_ener_adjust = Q_factor( (Word16) st->hBWE_FD->prev_fb_ener_adjust ); Q_fb_state_lpc_syn = Q_factor_arr( hBWE_TD->fb_state_lpc_syn, 10 ); Q_genSHBsynth_Hilbert_Mem = Q_factor_arrL( hBWE_TD->genSHBsynth_Hilbert_Mem, 21 ); Q_genSHBsynth_state_lsyn_filt_shb_local = Q_factor_arr( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 6 ); @@ -878,7 +941,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( fixedToFloat_arr( hBWE_TD->int_3_over_2_tbemem_dec_fx, hBWE_TD->int_3_over_2_tbemem_dec, Q_int_3_over_2_tbemem_dec, 15 ); fixedToFloat_arr( hBWE_TD->mem_resamp_HB_32k_fx, hBWE_TD->mem_resamp_HB_32k, Q_mem_resamp_HB_32k, 7 ); // bool des = ( st->bwidth == WB && st->last_extl != WB_TBE ) || ( st->bwidth == SWB && st->last_extl != SWB_TBE ) || ( st->bwidth == FB && st->last_extl != FB_TBE ); - st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); + //st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat( st->prev_fb_ener_adjust_fx, Q_prev_fb_ener_adjust ); } st->preemph_fac_float = fixedToFloat( st->preemph_fac, 15 ); IF( st->hTECDec != NULL ) @@ -959,8 +1022,8 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st->hTcxDec->conLastFrameLevel_e = 0; FOR( i = 0; i < PLC_MIN_STAT_BUFF_SIZE; i++ ) { - st->hTcxDec->NoiseLevelMemory_bfi[i] = fixedToFloat( st->hTcxDec->NoiseLevelMemory_bfi_fx[i], 15 ); - st->hTcxDec->conNoiseLevelMemory[i] = st->hTcxDec->NoiseLevelMemory_bfi_fx[i]; + //st->hTcxDec->NoiseLevelMemory_bfi[i] = me2f_16(st->hTcxDec->conNoiseLevelMemory[i], st->hTcxDec->conNoiseLevelMemory_e[i]); + //st->hTcxDec->conNoiseLevelMemory[i] = st->hTcxDec->NoiseLevelMemory_bfi_fx[i]; } st->hTcxDec->cummulative_damping_tcx_float = fixedToFloat( st->hTcxDec->cummulative_damping_tcx, 15 ); } @@ -1004,14 +1067,12 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st->hBPF->pst_mem_deemp_err = 0; } - st->past_gpit_float = fixedToFloat( st->past_gpit, 0 ); - st->past_gcode_float = fixedToFloat( st->past_gcode, 0 ); fixedToFloat_arr( st->Aq_cng, st->Aq_cng_float, 2, M ); - if ( st->last_gain_syn_deemph == 16384 ) - { - st->last_gain_syn_deemph_float = 1; - } + //if ( st->last_gain_syn_deemph == 16384 ) + //{ + // st->last_gain_syn_deemph_float = 1; + //} st->last_concealed_gain_syn_deemph_float = fixedToFloat( st->last_concealed_gain_syn_deemph, 14 ); st->enr_old = fixedToFloat( st->enr_old_fx, 0 ); st->lp_gainc = fixedToFloat( st->lp_gainc_fx, 3 ); @@ -1023,18 +1084,13 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( } st->old_fpitch_float = fixedToFloat( st->old_fpitch, 16 ); - FOR( i = 0; i < 8; i++ ) - { - st->dispMem[i] = 0; - } + IF( st->hTcxLtpDec != NULL ) { Q_tcxltp_mem_in = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_in_float, TCXLTP_MAX_DELAY ); Q_tcxltp_mem_out = Q_factor_arr( st->hTcxLtpDec->tcxltp_mem_out_float, L_FRAME48k ); - Q_tcxltp_gain_post_prev = Q_factor( st->hTcxLtpDec->tcxltp_gain_post_prev_float ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, Q_tcxltp_mem_in, TCXLTP_MAX_DELAY ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, Q_tcxltp_mem_out, L_FRAME48k ); - st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, Q_tcxltp_gain_post_prev ); } IF( st->hTonalMDCTConc ) { @@ -1128,7 +1184,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( //st->hPlcInfo->recovery_gain = (Word16) floatToFixed( st->hPlcInfo->recovery_gain_float, Q14 ); //st->hPlcInfo->step_concealgain_fx = (Word16) floatToFixed( st->hPlcInfo->step_concealgain, Q15 ); } - floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); + //floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); @@ -1201,7 +1257,7 @@ void stereo_tcx_dec_mode_switch_reconf_To_fixed_2( st->hTcxDec->cummulative_damping_tcx = float_to_fix16( st->hTcxDec->cummulative_damping_tcx_float, Q15 ); // st->Mode2_lp_gainp = float_to_fix(st->lp_gainp, Q16); st->Mode2_lp_gainp = float_to_fix( st->lp_gainp, Q29 ); - f2me_16( st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e ); + //f2me_16( st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e ); f2me_16( st->last_concealed_gain_syn_deemph_float, &st->last_concealed_gain_syn_deemph, &st->last_concealed_gain_syn_deemph_e ); //st->last_concealed_gain_syn_deemph = float_to_fix16( st->last_concealed_gain_syn_deemph_float, Q14 ); //st->last_concealed_gain_syn_deemph_e = 1; @@ -1313,7 +1369,7 @@ void fixed_to_float_stereo_tcx_core_dec( st->old_fpitch_float = fix_to_float( st->old_fpitch, Q16 ); for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) { - st->hTcxDec->NoiseLevelMemory_bfi[p] = fixedToFloat( st->hTcxDec->conNoiseLevelMemory[p], 15 - st->hTcxDec->conNoiseLevelMemory_e[p] ); + //st->hTcxDec->NoiseLevelMemory_bfi[p] = fixedToFloat( st->hTcxDec->conNoiseLevelMemory[p], 15 - st->hTcxDec->conNoiseLevelMemory_e[p] ); } fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); st->hTcxDec->CngLevelBackgroundTrace_bfi = fixedToFloat( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); @@ -1449,7 +1505,7 @@ void fixed_to_float_stereo_tcx_core_dec( } } - st->last_gain_syn_deemph_float = fixedToFloat(st->last_gain_syn_deemph, 15 - st->last_gain_syn_deemph_e); + //st->last_gain_syn_deemph_float = fixedToFloat(st->last_gain_syn_deemph, 15 - st->last_gain_syn_deemph_e); st->hTcxDec->old_gaintcx_bfi_float = fixedToFloat(st->hTcxDec->old_gaintcx_bfi, 15 - st->hTcxDec->old_gaintcx_bfi_e); st->hTcxDec->cummulative_damping_tcx_float = fix16_to_float(st->hTcxDec->cummulative_damping_tcx, Q15); st->hTcxDec->damping_float = fix16_to_float(st->hTcxDec->damping, Q14); diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index fb40d730331d5139dbe63135d986d361c1751bc3..0312cd09cbfc07111d2a19991e56f7ca23fe5634 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -49,6 +49,8 @@ #ifdef IVAS_FLOAT_FIXED #define _180_OVER_PI_Q25 1922527233 #define _180_OVER_PI_FX (Word32) (( 180.0f / EVS_PI ) *ONE_IN_Q10) +#define PI_OVER_180_Q15 ( 572 ) +#define _180_OVER_PI_Q9 ( 29335 ) #define PI_OVER_4_Q29 421657440 #define _180_OVER_PI_Q9 ( 29335 ) #define PI_OVER_Q29 1686629760 @@ -1337,7 +1339,9 @@ typedef enum #define MCMASA_LFE_BETA 0.09f #define MCMASA_LFE_THETA 1.3f #define MCMASA_LFE_SYNTH_ALPHA 0.95f /* Smoothing coefficient for LFE synthesis */ - +#ifdef IVAS_FLOAT_FIXED +#define MCMASA_LFE_SYNTH_ALPHA_Q15 (31129) +#endif #define MCMASA_LFE_ALPHA_Q15 (21954) #define MCMASA_LFE_BETA_Q15 (2949) #define MCMASA_LFE_BETA_Q14 (1474) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index dbcf4d4b8035584d0ab74df5978b3dd46962f8bd..150f0a91271ff2af517ef8936e553bf5bbeb94d1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -6933,6 +6933,16 @@ void ivas_omasa_dirac_rend_jbm( float *output_f[] /* o : rendered time signal */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( + Decoder_Struct *st_ivas, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word16 *cldfb_buf_q, + const Word16 nBins, + const Word16 subframe +); +#endif void ivas_omasa_preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f8a66b48709b8dedacbc2530186229ca0d204876..d890a09321a661e44bba1b354db2102be45b947d 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1269,9 +1269,10 @@ void stereo_icBWE_decproc_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis */ Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ - const int16_t last_core, /* i : last core, primary channel */ - const int16_t last_bwidth, /* i : last bandwidth */ - const int16_t output_frame /* i : frame length */ + const Word16 last_core, /* i : last core, primary channel */ + const Word16 last_bwidth, /* i : last bandwidth */ + const Word16 output_frame, /* i : frame length */ + Word16 q_output /* i : Q-fac of output */ ); void add_HB_to_mono_dmx_fx( @@ -1972,6 +1973,24 @@ void ivas_mct_side_bits_fx( const Word16 nb_bits_metadata /* i : number of metadata bits */ ); +#ifdef BASOP_NOGLOB /*Critical overflow */ +Flag conv_fx_32( +#else +void conv_fx_32( +#endif + const Word16 x[], /* i : i vector Q_new*/ + const Word16 h[], /* i : impulse response (or second i vector) Q(15)*/ + Word32 y[], /* o : output vetor (result of convolution) 12 bits*/ + const Word16 L /* i : vector size */ +); + +void stereo_dtf_cng_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + const Word16 output_frame, /* i : output frame size */ + Word16 q_dft /* i : Q factor of the DFT data */ +); #endif // IVAS_FLOAT_FIXED diff --git a/lib_com/ivas_stereo_ica_com_fx.c b/lib_com/ivas_stereo_ica_com_fx.c index 1e6c2bb84dff30c9cf55b2914ca09ce08f29399c..04d8a6c8e1a8af9231e83f61ef10aee446cb371f 100644 --- a/lib_com/ivas_stereo_ica_com_fx.c +++ b/lib_com/ivas_stereo_ica_com_fx.c @@ -188,20 +188,8 @@ static void interpTargetChannel_fx( ptr2_fx[i] = 0; /* lim1 = ceil((i - SINC_ORDER1)*SPREAD_FACTOR1); */ /* lim2 = floor((i + SINC_ORDER1)*SPREAD_FACTOR1); */ - temp_int = shr( ( i - SINC_ORDER1 ), 1 ); - tempF_fx = ( i - SINC_ORDER1 ) % 2; //*SPREAD_FACTOR1 - lim1 = (Word16) ( temp_int ); - IF( tempF_fx == 1 ) - { - lim1++; - } - tempF_fx = ( i + SINC_ORDER1 ) % 2; //*SPREAD_FACTOR1 - temp_int = shr( ( i + SINC_ORDER1 ), 1 ); //*SPREAD_FACTOR1 - lim2 = (Word16) ( temp_int ); - IF( tempF_fx == -1 ) - { - lim2--; - } + lim1 = add(shr((i - SINC_ORDER1), 1), 1); + lim2 = shr((i + SINC_ORDER1), 1); FOR( j = lim1; j <= lim2; j++ ) { ptr2_fx[i] = L_add( Mpy_32_32( win_fx[j * INTERP_FACTOR1 - i], ptr1_fx[j] ), ptr2_fx[i] ); diff --git a/lib_com/prot_fx1.h b/lib_com/prot_fx1.h index 3654f330a994b64f331b4f474fd6c93865b34863..9ddacf686372e8ab4604258edf4d30653a7e3b20 100644 --- a/lib_com/prot_fx1.h +++ b/lib_com/prot_fx1.h @@ -183,6 +183,11 @@ Word16 maximum_fx( /* o : index of the maximum value i const Word16 lvec_fx, /* i : length of input vector */ Word16 *max_fx /* o : maximum value in the input vector */ ); +Word16 minimum_abs32_fx( /* o : index of the minimum value in the input vector */ + const Word32 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word32 *min_fx /* o : minimum value in the input vector */ +); Word16 minimum_32_fx( /* o : index of the minimum value in the input vector */ const Word32 *vec_fx, /* i : input vector */ const Word16 lvec_fx, /* i : length of input vector */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 362e51c917c3d4519959c801c0ad58c518772fa8..da05689395cf460b8d657122e5f0d725e0619655 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -93,6 +93,8 @@ void floatToFixed_arrL( float * f, Word32* i, Word16 Q, Word16 l); void floatToFixed_arr( float * f, Word16* i, Word16 Q, Word16 l); void fixedToFloat_arrL( Word32 *i, float * f, Word16 Q, Word16 l); void fixedToFloat_arr( Word16 *i, float * f, Word16 Q, Word16 l); +void floatToFixed_arrL32(float * f, Word32* i, Word16 Q, Word16 l); +void fixedToFloat_arrL32(Word32 *i, float * f, Word16 Q, Word16 l); Word16 Q_factor(float x); Word16 Q_factor_L(float x); Word16 Q_factor_arr(float* x, Word16 l); @@ -100,6 +102,8 @@ Word16 Q_factor_arrL(float* x, Word16 l); //Handles the cases where Q is negative Word32 floatToFixed( float f, Word16 Q); float fixedToFloat( Word32 i, Word16 Q); +Word32 floatToFixed_32(float f, Word16 Q); +float fixedToFloat_32(Word32 i, Word16 Q); void floatToFixed_arr16(float *f, Word16 *i, Word16 Q, Word16 l); void floatToFixed_arr32(float *f, Word32 *i, Word16 Q, Word16 l); @@ -7080,6 +7084,7 @@ void GSC_dec_init_ivas_fx( Word16 *timeDomainInput, /* i : pointer to time domain input */ Word16 Q, Word32 *powerSpectrum, + Word16 Q_power_spectrum, Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ @@ -7110,6 +7115,7 @@ void GSC_dec_init_ivas_fx( const Word16 *timeDomainInput, /* i: pointer to time domain input */ const Word16 Q, Word32 *power_spectrum, + Word16 Q_power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 element_mode, /* i : element mode */ const Word16 bwidth, /* i : audio bandwidth */ diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index ce5353b2091675a7ad5446298c6061ed67d596af..dea15c15ad1ceb6051c2099da2d52d1090620529 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -461,6 +461,7 @@ typedef struct Word16 exp_cldfb_periodog; Word32 cngNoiseLevel[FFTCLDFBLEN]; /* Noise level applied for the CNG in each (sub)band */ + Word16 q_cngNoiseLevel; Word16 cngNoiseLevelExp; int16_t seed; /* Seed memory (for random function) */ diff --git a/lib_com/tools_fx.c b/lib_com/tools_fx.c index bba479099e4b0044b710b2146b3eb2950838572a..2ae58f5a06a3ddfc2994f2acfa8a2047d5e0abe0 100644 --- a/lib_com/tools_fx.c +++ b/lib_com/tools_fx.c @@ -79,6 +79,7 @@ float fix_to_float( Word32 number, Word32 Q ) Word16 float_to_fix16( float number, Word16 Q ) { assert( Q >= 0 ); + IF(isnan(number)) return 0; if ( number == 1.0f && Q == Q15 ) return MAX16B; assert( fabs( number ) < pow( 2, 15 - Q ) ); @@ -1048,6 +1049,41 @@ Word16 maximum_fx( /* o : index of the maximum value in the input vecto return ind; } +/*---------------------------------------------------------------------* + * minimum_abs32_fx() + * + * Find index and value of the absolute minimum in a vector + *---------------------------------------------------------------------*/ +Word16 minimum_abs32_fx( /* o : index of the minimum value in the input vector */ + const Word32 *vec_fx, /* i : input vector */ + const Word16 lvec_fx, /* i : length of input vector */ + Word32 *min_fx /* o : minimum value in the input vector */ +) +{ + Word16 j, ind; + Word16 tmp; + ind = 0; + move16(); + tmp = vec_fx[0]; + move16(); + + FOR ( j=1 ; jhFdCngDec->bandNoiseShape[p] = (Word32) ( st->hFdCngDec->bandNoiseShape_float[p] * ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); }*/ - ApplyFdCng_fx( NULL, 0, NULL, NULL, NULL, NULL, st, 0, 0 ); + ApplyFdCng_fx( NULL, 0, NULL, 0, NULL, NULL, NULL, st, 0, 0 ); if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) { Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); @@ -630,7 +630,7 @@ ivas_error acelp_core_dec_ivas_fx( } //st->bfi_pitch *= tmpF; //st->bfi_pitch_frame = L_FRAME; - st->bfi_pitch = mult_r(st->bfi_pitch, tmpF_fx); + st->bfi_pitch_fx = mult_r(st->bfi_pitch_fx, tmpF_fx); st->bfi_pitch_frame = L_FRAME; move16(); } @@ -656,7 +656,7 @@ ivas_error acelp_core_dec_ivas_fx( } //st->bfi_pitch *= tmpF; //st->bfi_pitch_frame = L_FRAME16k; - st->bfi_pitch = mult_r( shl_sat( st->bfi_pitch, exp ), tmpF_fx ); + st->bfi_pitch_fx = mult_r( shl_sat( st->bfi_pitch_fx, exp ), tmpF_fx ); st->bfi_pitch_frame = L_FRAME16k; move16(); } @@ -785,7 +785,7 @@ ivas_error acelp_core_dec_ivas_fx( Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp - new_cngNoiseLevelExp); st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = new_cngNoiseLevelExp; - ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); + ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); if (st->hFdCngDec->hFdCngCom->cngNoiseLevelExp < 0) { Scale_sig32(st->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, st->hFdCngDec->hFdCngCom->cngNoiseLevelExp); @@ -1820,7 +1820,7 @@ ivas_error acelp_core_dec_ivas_fx( st->hFdCngDec->hFdCngCom->sidNoiseEstExp = 31 - Q4; // Q4 /*==========================================================*/ //ApplyFdCng_fx( syn_fx + L_SUBFR, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, ( st->coder_type == AUDIO && !st->GSC_noisy_speech ) ); - ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); /*==========================================================*/ if (st->hFdCngDec->partNoiseShape_exp < 0) { Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, st->hFdCngDec->partNoiseShape_exp); @@ -2065,7 +2065,7 @@ ivas_error acelp_core_dec_ivas_fx( //st->hFdCngDec->partNoiseShape_exp = 31 - Q4; // Q4 //floatToFixed_arrL(st->hFdCngDec->partNoiseShape_float, st->hFdCngDec->partNoiseShape, Q31 - st->hFdCngDec->partNoiseShape_exp, NPART); - ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); + ApplyFdCng_fx(psyn_fx, st->Q_syn, NULL, 0, realBuffer_fx, imagBuffer_fx, NULL, st, 0, (st->coder_type == AUDIO && !st->GSC_noisy_speech)); if (st->hFdCngDec->partNoiseShape_exp < 0) { Scale_sig32(st->hFdCngDec->partNoiseShape, NPART, -st->hFdCngDec->partNoiseShape_exp); st->hFdCngDec->partNoiseShape_exp = 0; @@ -2821,7 +2821,8 @@ ivas_error acelp_core_dec_ivas_fx( Word16 tmp_exp = 0; //Word16 output_subfr = output_frame / NB_SUBFR; - Copy_Scale_sig_32_16(synth_fx, synth_fx16, 0, L_FRAME48k); + Copy_Scale_sig_32_16(synth_fx, synth_fx16, L_FRAME48k, 0); + hf_synth_ivas_fx( st->hBWE_zero, st->core_brate, output_frame, Aq_fx, exc_fx, psyn_fx, synth_fx16, st->Q_exc, st->Q_syn2, st->hBWE_zero->delay_syn_hf_fx, &tmp_exp, st->hBWE_zero->mem_hp_interp_fx, st->extl, st->CNG_mode, st->element_mode ); @@ -3004,22 +3005,11 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /* dec_exc */ st->lp_gainc_fx = float_to_fix16(st->lp_gainc, Q3); - st->dm_fx.prev_state = float_to_fix16(st->dispMem[0], 0); - st->dm_fx.prev_gain_code = floatToFixed(st->dispMem[1], Q16); - floatToFixed_arr(&(st->dispMem[2]), st->dm_fx.prev_gain_pit, Q14, 6); - st->prev_gain_pit_dec_fx = float_to_fix16(st->prev_gain_pit_dec, Q14); - st->prev_tilt_code_dec_fx = float_to_fix16(st->prev_tilt_code_dec, Q15); st->lp_gainp_fx = float_to_fix16(st->lp_gainp, Q14); - st->past_gpit = float_to_fix16(st->past_gpit_float, Q14); - - /* Bad frame */ - - st->ge_sm_fx = (Word16)floatToFixed(st->ge_sm, st->Q_stat_noise_ge); - /* After dec_exc */ st->enr_old_fx = floatToFixed(st->enr_old, 0); - st->exc_pe_fx = (Word16)floatToFixed(st->exc_pe, st->Q_stat_noise); + //st->exc_pe_fx = (Word16)floatToFixed(st->exc_pe, st->Q_stat_noise); floatToFixed_arr(st->syn_float, st->syn, 0, M + 1); /* CLDFB */ @@ -3050,20 +3040,6 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte st->hBPF->psf_att_fx = float_to_fix16(st->hBPF->psf_att, Q15); } - /*ZERO_BWE_DEC_HANDLE*/ - if (st->hBWE_zero) { - floatToFixed_arr(st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, 0, 4); - if (st->hBWE_FD) { - floatToFixed_arr(st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, -2 - st->hBWE_FD->memExp1, L_FIR - 1); - } - else { - floatToFixed_arr(st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, -2, L_FIR - 1); - } - floatToFixed_arr(st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, 0, M); - floatToFixed_arr(st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); - floatToFixed_arr(st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); - } - //FdCng if ( st->hFdCngDec ) { @@ -3158,10 +3134,10 @@ void acelp_decoder_state_float2fix(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte } /*FD_BWE_DEC_HANDLE*/ - if (st->hBWE_FD) { - floatToFixed_arr(st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); - st->hBWE_FD->mem_deemph_old_syn_fx = extract_l( floatToFixed( st->hBWE_FD->mem_deemph_old_syn, -1 ) ); - } + //if (st->hBWE_FD) { + // floatToFixed_arr(st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + // st->hBWE_FD->mem_deemph_old_syn_fx = extract_l( floatToFixed( st->hBWE_FD->mem_deemph_old_syn, -1 ) ); + //} } @@ -3201,20 +3177,7 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /* dec_exc */ st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); - st->dispMem[0] = fixedToFloat(st->dm_fx.prev_state, 0); - st->dispMem[1] = fixedToFloat(st->dm_fx.prev_gain_code, Q16); - fixedToFloat_arr(st->dm_fx.prev_gain_pit, &(st->dispMem[2]), Q14, 6); - - st->prev_gain_pit_dec = fixedToFloat(st->prev_gain_pit_dec_fx, Q14); - st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); st->lp_gainp = fixedToFloat(st->lp_gainp_fx, Q14); - st->lp_gainc = fixedToFloat(st->lp_gainc_fx, Q3); - st->past_gpit_float = fixedToFloat(st->past_gpit, Q14); - - /* Bad frame */ - st->ge_sm = fixedToFloat(st->ge_sm_fx, st->Q_stat_noise_ge); - st->exc_pe = fixedToFloat(st->exc_pe_fx, st->Q_stat_noise); - /* After dec_exc */ st->enr_old = fixedToFloat(st->enr_old_fx, 0); @@ -3245,20 +3208,6 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte st->hBPF->psf_att = fixedToFloat(st->hBPF->psf_att_fx, Q15); } - /*ZERO_BWE_DEC_HANDLE*/ - if (st->hBWE_zero) { - fixedToFloat_arr(st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, 0, 4); - if (st->hBWE_FD) { - fixedToFloat_arr(st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, -2 - st->hBWE_FD->memExp1, L_FIR - 1); - } - else { - fixedToFloat_arr(st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, -2, L_FIR - 1); - } - fixedToFloat_arr(st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, 0, M); - fixedToFloat_arr(st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, 0, NS2SA(16000, DELAY_CLDFB_NS)); - fixedToFloat_arr(st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, 0, INTERP_3_1_MEM_LEN); - } - //FdCng if ( st->hFdCngDec ) { @@ -3401,8 +3350,8 @@ void acelp_decoder_state_fix2float(Decoder_State *st, STEREO_CNG_DEC_HANDLE hSte /*FD_BWE_DEC_HANDLE*/ if (st->hBWE_FD) { - fixedToFloat_arr(st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); - st->hBWE_FD->mem_deemph_old_syn = fixedToFloat(st->hBWE_FD->mem_deemph_old_syn_fx, -1); + //fixedToFloat_arr(st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, -1, NS2SA(16000, DELAY_FD_BWE_ENC_NS)); + //st->hBWE_FD->mem_deemph_old_syn = fixedToFloat(st->hBWE_FD->mem_deemph_old_syn_fx, -1); } } diff --git a/lib_dec/acelp_core_switch_dec.c b/lib_dec/acelp_core_switch_dec.c index de7719a779a976b596a3091728f5f10ce34c54b2..d64f3d9d1da5fd9c5a4bbd9ae4b91598adba61ae 100644 --- a/lib_dec/acelp_core_switch_dec.c +++ b/lib_dec/acelp_core_switch_dec.c @@ -334,7 +334,7 @@ ivas_error acelp_core_switch_dec( * * ACELP core decoder in the first ACELP->HQ switching frame in case of BAD frame *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) ivas_error acelp_core_switch_dec_bfi( Decoder_State *st /* i/o: decoder state structure */ ) @@ -525,7 +525,7 @@ ivas_error acelp_core_switch_dec_bfi( return error; } - +#endif /*-------------------------------------------------------------------* * decod_gen_voic_core_switch() diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index 234a7b78eb6d03c56f672d792af54c9fd794591f..6138fa360a11b9e39d3faf911f599d652e66cc50 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -833,7 +833,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( Copy_Scale_sig_32_16(synth32, synth_out, L_FRAME48k, -5); /* output to Q0 */ - Copy_Scale_sig32_16(syn32, synth_out, L_FRAME48k, -5); + Copy_Scale_sig32_16(syn32, synth_out, L_FRAME16k, -5); //Scale_sig(synth_out,L_FRAME48k, negate(st_fx->Q_syn)); cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); diff --git a/lib_dec/core_dec_init.c b/lib_dec/core_dec_init.c index b01f2d0581777dfc933897182f7e8829c751f694..fb6a51f469d316b56a34c895c5f50950fa482dc2 100644 --- a/lib_dec/core_dec_init.c +++ b/lib_dec/core_dec_init.c @@ -745,7 +745,7 @@ void tcxltp_dec_init( #endif // IVAS_FLOAT_FIXED hTcxLtpDec->tcxltp_pitch_int_post_prev = 0; hTcxLtpDec->tcxltp_pitch_fr_post_prev = 0; - hTcxLtpDec->tcxltp_gain_post_prev_float = 0.f; + //hTcxLtpDec->tcxltp_gain_post_prev_float = 0.f; #ifdef IVAS_FLOAT_FIXED hTcxLtpDec->tcxltp_gain_post_prev = 0; #endif // IVAS_FLOAT_FIXED diff --git a/lib_dec/core_dec_init_fx.c b/lib_dec/core_dec_init_fx.c index e4c253c92b8d3e8ca1d836c2680de16309ffb694..4b4b0346fe889733c01c77224dba2a15a5357f59 100644 --- a/lib_dec/core_dec_init_fx.c +++ b/lib_dec/core_dec_init_fx.c @@ -1695,7 +1695,8 @@ void open_decoder_LPD_ivas_fx( st->hTcxDec->NoiseLevelIndex_bfi = PLC_MIN_STAT_BUFF_SIZE - 1; st->hTcxDec->CurrLevelIndex_bfi = 0; st->hTcxDec->LastFrameLevel_bfi_fx = PLC_MIN_CNG_LEV; - set16_fx( st->hTcxDec->NoiseLevelMemory_bfi_fx, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); + set16_fx( st->hTcxDec->conNoiseLevelMemory, PLC_MIN_CNG_LEV, PLC_MIN_STAT_BUFF_SIZE ); + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); st->hTcxDec->cummulative_damping_tcx = 32767 /*1.0f Q15*/; diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index bc416760805b0a83feb64291c6e349deb04151f3..a78ab12114545b16138d49eddf17379edba573e8 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -403,7 +403,7 @@ ivas_error core_switching_pre_dec_ivas_fx( #if 1 /*To be removed later: floating point initializations*/ st->tilt_code = 0.0f; st->gc_threshold = 0.0f; - set_f( st->dispMem, 0, 8 ); + //set_f( st->dispMem, 0, 8 ); #endif st->tilt_code_fx = 0; st->gc_threshold_fx = 0; @@ -478,7 +478,7 @@ ivas_error core_switching_pre_dec_ivas_fx( #if 1 st->tilt_code = 0.0f; st->gc_threshold = 0.0f; - set_f( st->dispMem, 0, 8 ); + //set_f( st->dispMem, 0, 8 ); #endif st->tilt_code_fx = 0; @@ -708,7 +708,7 @@ ivas_error core_switching_pre_dec_ivas_fx( return error; } #endif // IVAS_FLOAT_FIXED - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) ivas_error core_switching_pre_dec( Decoder_State *st, /* i/o: decoder state structure */ const int16_t output_frame, /* i : frame length */ @@ -1201,8 +1201,8 @@ ivas_error core_switching_pre_dec( return error; } - - +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * core_switching_post_dec() * @@ -1673,7 +1673,7 @@ ivas_error core_switching_post_dec( return error; } - +#endif /*---------------------------------------------------------------------* * core_switching_hq_prepare_dec() * @@ -1928,7 +1928,7 @@ void bandwidth_switching_detect_ivas_fx( * * Band-width switching pre-processing *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void bw_switching_pre_proc( Decoder_State *st, /* i/o: decoder state structure */ const float *old_syn_12k8_16k, /* i : ACELP core synthesis at 12.8kHz or 16kHz */ @@ -2033,7 +2033,7 @@ void bw_switching_pre_proc( return; } - +#endif #ifdef IVAS_FLOAT_FIXED void ivas_bw_switching_pre_proc_fx( Decoder_State *st, /* i/o: decoder state structure */ @@ -2159,12 +2159,12 @@ void ivas_bw_switching_pre_proc_fx( IF ( EQ_16( st->last_bwidth, 0 ) && LE_16( st->extl, SWB_CNG ) ) { - st->prev_ener_shb = 0.0f; + //st->prev_ener_shb = 0.0f; st->prev_ener_shb_fx = 0; IF( st->hBWE_FD != NULL ) { - set_f( st->hBWE_FD->prev_SWB_fenv, 0, SWB_FENV ); + //set_f( st->hBWE_FD->prev_SWB_fenv, 0, SWB_FENV ); set_s( st->prev_SWB_fenv_fx, 0, SWB_FENV ); } } diff --git a/lib_dec/dec_LPD.c b/lib_dec/dec_LPD.c index bcba3ef8e757fd8ce22bc1bf668a6e7fd4a18d56..a307cba3a0b4b0ec27d05d40383bddc21de97a28 100644 --- a/lib_dec/dec_LPD.c +++ b/lib_dec/dec_LPD.c @@ -52,7 +52,7 @@ * * Core decoder MODE2 *--------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decoder_LPD_flt( Decoder_State *st, /* i/o: decoder memory state pointer */ float signal_out[], /* o : signal with LPD delay (7 subfrs) */ @@ -787,3 +787,4 @@ void decoder_LPD_flt( return; } +#endif \ No newline at end of file diff --git a/lib_dec/dec_ace.c b/lib_dec/dec_ace.c index 84717665ab4f63390835cbcb3ce748ef1e9bbaba..a643e05c23848349b5f9a68387ef67e0d250f4c2 100644 --- a/lib_dec/dec_ace.c +++ b/lib_dec/dec_ace.c @@ -40,7 +40,7 @@ #include #include "rom_com.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decoder_acelp_flt() * @@ -540,3 +540,4 @@ void decoder_acelp_flt( return; } +#endif diff --git a/lib_dec/dec_amr_wb.c b/lib_dec/dec_amr_wb.c index ce636756a866bca085a9411da92ca8bb2d83ca4e..7ddb784cc923faa357fc33f9264840b211f3c525 100644 --- a/lib_dec/dec_amr_wb.c +++ b/lib_dec/dec_amr_wb.c @@ -46,7 +46,7 @@ * * Decode excitation signal in AMR-WB IO mode *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decod_amr_wb( Decoder_State *st, /* i/o: decoder static memory */ const float *Aq, /* i : LP filter coefficients */ @@ -168,3 +168,4 @@ void decod_amr_wb( return; } +#endif diff --git a/lib_dec/dec_gen_voic.c b/lib_dec/dec_gen_voic.c index e555faec3fd4902710d69ad2e5e0ae121156318f..a62b3f40864fa814d0b8fb3aff70e1922c252adc 100644 --- a/lib_dec/dec_gen_voic.c +++ b/lib_dec/dec_gen_voic.c @@ -40,7 +40,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * decod_gen_voic() * @@ -292,3 +292,4 @@ ivas_error decod_gen_voic( return error; } +#endif diff --git a/lib_dec/dec_nelp.c b/lib_dec/dec_nelp.c index 586df0f7adcc2a9c109284902e9f7899bba4f43f..80e86881f8c2ec5bc31929e2393e63dcbafb8625 100644 --- a/lib_dec/dec_nelp.c +++ b/lib_dec/dec_nelp.c @@ -39,7 +39,7 @@ #include "cnst.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decod_nelp() * @@ -99,3 +99,4 @@ void decod_nelp( return; } +#endif diff --git a/lib_dec/dec_ppp.c b/lib_dec/dec_ppp.c index 58d21e75c6ed02dc1a43c2442ea504d18f594404..5e2d86a69cfc47b43fd048429f88ec4542475558 100644 --- a/lib_dec/dec_ppp.c +++ b/lib_dec/dec_ppp.c @@ -39,7 +39,7 @@ #include "cnst.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*------------------------------------------------------------------- * decod_ppp() * @@ -106,3 +106,4 @@ ivas_error decod_ppp( return error; } +#endif diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 8c9a9958a923198527b3fe25d2e3cc3333f70ab7..40d306a9bb0a6c6d7316b68aaebdf2d07ffa41a7 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -761,7 +761,7 @@ void IMDCT_flt( * * TCX: inverse quantization *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decoder_tcx_invQ( Decoder_State *st, /* i/o: coder memory state */ int16_t prm[], /* i : parameters */ @@ -1152,7 +1152,6 @@ void decoder_tcx_invQ( return; } -#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decoder_tcx_noisefilling() * diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index acdba363cb93ced038341a801a070934ff048882..9c62308b7cc74adb723c266d4c66d3d13bc97852 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -1710,7 +1710,8 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, #else tmp1 = round_fx(L_shl(tmp32, tmp2)); #endif - s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); + //s = sub(sub(sub(1, shl(s, 1)), 6/*table lookup for inverse framelength*/), tmp2); + s = sub(25, add(shl(add(-2, s), 1), tmp2)); tmp1 = Sqrt16(tmp1, &s); move16(); level_syn = tmp1; /*Q0*/ @@ -1718,7 +1719,7 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, /* PLC: [TCX: Fade-out] * PLC: estimate and update CNG energy */ - level_syn_e = add(s,15); + level_syn_e = s;// add(s, 15); test(); test(); IF (bfi == 0 && st_fx->tcxonly != 0 && ( NE_16(st_fx->element_mode, IVAS_CPE_MDCT) || MCT_flag ) && EQ_16(st_fx->clas_dec , UNVOICED_CLAS)) @@ -1728,8 +1729,8 @@ void decoder_tcx_post_ivas_fx(Decoder_State *st_fx, Qnew_levelBackgroundTrace = 0; move16(); minimumStatistics(hTcxDec->conNoiseLevelMemory, /*Q15*/ - &hTcxDec->conNoiseLevelIndex, /*Q0 */ - &hTcxDec->conCurrLevelIndex, /*Q0 */ + &hTcxDec->NoiseLevelIndex_bfi, /*Q0 */ + &hTcxDec->CurrLevelIndex_bfi, /*Q0 */ &hTcxDec->conCngLevelBackgroundTrace, /*Q15*/ &hTcxDec->conLastFrameLevel, /*Q15*/ level_syn, /*Q15*/ diff --git a/lib_dec/dec_tran.c b/lib_dec/dec_tran.c index 900212817e122dcdeaa6e4f9e046f05f99fc9858..65878183e15280237484c10c9e54ac484836be92 100644 --- a/lib_dec/dec_tran.c +++ b/lib_dec/dec_tran.c @@ -45,7 +45,7 @@ * * Decode transition (TC) frames *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decod_tran( Decoder_State *st, /* i/o: decoder static memory */ const int16_t L_frame, /* i : length of the frame */ @@ -195,3 +195,4 @@ void decod_tran( return; } +#endif diff --git a/lib_dec/dec_uv.c b/lib_dec/dec_uv.c index 05d139ea261cfd203a8c859d32c4ace6b9adebed..34866754ac0349c76b1b2cc2f0af4f293532a047 100644 --- a/lib_dec/dec_uv.c +++ b/lib_dec/dec_uv.c @@ -38,7 +38,7 @@ #include "options.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * decod_unvoiced() * @@ -166,3 +166,4 @@ void decod_unvoiced( return; } +#endif diff --git a/lib_dec/er_dec_acelp.c b/lib_dec/er_dec_acelp.c index 3bd3d522b649290645613610bd765c06cd376761..01eb2389a32d405cb018f988f9871987705b4fa3 100644 --- a/lib_dec/er_dec_acelp.c +++ b/lib_dec/er_dec_acelp.c @@ -40,7 +40,7 @@ #include #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * con_acelp_flt() * @@ -721,3 +721,4 @@ void con_acelp_flt( return; } +#endif diff --git a/lib_dec/er_util_fx.c b/lib_dec/er_util_fx.c index 34968d8f7e810b59b6f829778eb95c0ec88a27d5..fff93ee219eea52765b7e6cc0b6ee246e90f2a86 100644 --- a/lib_dec/er_util_fx.c +++ b/lib_dec/er_util_fx.c @@ -119,6 +119,12 @@ void minimumStatistics( tmp = mult_r(tmp,currentFrameLevel); /*Q_tmp = tmp2 + currentFrameLevel_e*/ tmp2 = add(tmp2,currentFrameLevel_e); + IF(EQ_16(tmp, 0)) + { + tmp2 = 0; + move16(); + } + *new_noiseEstimate_e = BASOP_Util_Add_MantExp(round_fx(tmp32),add(aOpt_e,noiseLevelMemory_e[tmp_e - 1]),negate(s_max(tmp,-32767)/*to avoid negate(-32768)*/),tmp2,&f); assert(f >= 0); diff --git a/lib_dec/evs_dec.c b/lib_dec/evs_dec.c index 76c2fe87249f156e7ac0e6ceeb0c46834bc4cb56..2f9e2e22ea4faa0f4d670f06984455e124ce62b7 100644 --- a/lib_dec/evs_dec.c +++ b/lib_dec/evs_dec.c @@ -46,7 +46,7 @@ #include "prot_fx2.h" #include "ivas_prot_fx.h" #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*--------------------------------------------------------------------------* * evs_dec_flt() * @@ -945,3 +945,4 @@ ivas_error evs_dec_flt( pop_wmops(); return error; } +#endif diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index f4ac3042e10cf629ff8b4803f8c0c338f25695b5..093f9552be775b796ef8ba41985298043fb745de 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -635,7 +635,7 @@ void deleteFdCngDec_flt( * * Apply the CLDFB-based CNG at the decoder *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void ApplyFdCng_flt( float *timeDomainInput, float *powerSpectrum, @@ -752,7 +752,7 @@ void ApplyFdCng_flt( } } - perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, 0, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) ) { @@ -906,7 +906,7 @@ void ApplyFdCng_flt( hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - hFdCngDec->msPeriodog_ST_exp ) ) ); } - perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, 0, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); for ( int p = 0; p < hFdCngDec->hFdCngCom->stopFFTbin - hFdCngDec->hFdCngCom->startBand; p++ ) { @@ -1032,7 +1032,7 @@ void ApplyFdCng_flt( hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - hFdCngDec->msPeriodog_ST_exp ) ) ); } - perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput_fx, q_tdi, powerSpectrum_fx, 0, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); for ( int p = 0; p < hFdCngDec->hFdCngCom->stopFFTbin - hFdCngDec->hFdCngCom->startBand; p++ ) { @@ -1156,7 +1156,6 @@ void ApplyFdCng_flt( return; } -#ifndef IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * perform_noise_estimation_dec_flt() * @@ -1501,7 +1500,7 @@ static void perform_noise_estimation_dec_flt( return; } -#endif // IVAS_FLOAT_FIXED +#endif /*------------------------------------------------------------------- * FdCng_decodeSID_flt() diff --git a/lib_dec/fd_cng_dec_fx.c b/lib_dec/fd_cng_dec_fx.c index 1970f0eedcbfd495c387ac0ec0935a136333c3bc..2803113c9cde9689eeab692f52e73797adba4e58 100644 --- a/lib_dec/fd_cng_dec_fx.c +++ b/lib_dec/fd_cng_dec_fx.c @@ -1174,6 +1174,7 @@ Word16 ApplyFdCng_fx( Word16 *timeDomainInput, /* i : pointer to time domain input */ Word16 Q, Word32 *powerSpectrum, + Word16 Q_power_spectrum, Word32 **cldfbBufferReal, /* i/o: real part of the CLDFB buffer */ Word32 **cldfbBufferImag, /* i/o: imaginary part of the CLDFB buffer */ Word16 *cldfbBufferScale, /* o : pointer to the scalefactor for real and imaginary part of the CLDFB buffer */ @@ -1264,7 +1265,7 @@ Word16 ApplyFdCng_fx( ( !st->BER_detect ) ) { /* Perform noise estimation at the decoder */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); /* Update the shaping parameters */ test(); @@ -1526,7 +1527,7 @@ Word16 ApplyFdCng_fx( IF( hFdCngCom->active_frame_counter > 0 ) { /* Perform noise estimation in active frames in the decoder for downward updates */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); } } test(); @@ -1585,7 +1586,7 @@ Word16 ApplyFdCng_fx( IF( st != NULL && EQ_16( st->cng_type, LP_CNG ) ) { /* Perform noise estimation on inactive phase at the decoder */ - perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); + perform_noise_estimation_dec_fx( timeDomainInput, Q, powerSpectrum, Q_power_spectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD ); /* Update the shaping parameters */ @@ -2330,6 +2331,7 @@ void perform_noise_estimation_dec_fx( const Word16 *timeDomainInput, /* i: pointer to time domain input */ const Word16 Q, Word32 *power_spectrum, + Word16 Q_power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */ const Word16 element_mode, /* i : element mode */ const Word16 bwidth, /* i : audio bandwidth */ @@ -2791,7 +2793,7 @@ void perform_noise_estimation_dec_fx( { /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */ periodog = power_spectrum; - periodog_exp = 31; + periodog_exp = 31 - Q_power_spectrum; } ELSE { diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c index bec4c17d269f9eb2d207720c4e5994b841d5e409..74ca281fa503c4cbedab79050fc89efc94687141 100644 --- a/lib_dec/gs_dec.c +++ b/lib_dec/gs_dec.c @@ -48,7 +48,7 @@ * * Decode audio (AC) frames *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decod_audio( Decoder_State *st, /* i/o: decoder static memory */ float dct_epit[], /* o : GSC excitation in DCT domain */ @@ -452,8 +452,9 @@ void decod_audio( return; } +#endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * gsc_dec() * @@ -698,7 +699,9 @@ void gsc_dec( return; } +#endif +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * GSC_dec_init_ivas() * @@ -725,3 +728,4 @@ void GSC_dec_init_ivas( return; } +#endif diff --git a/lib_dec/hf_synth.c b/lib_dec/hf_synth.c index 7af1f829174f0f4ccf472812f750ea64b317f9c9..25f94331caeec4e912d7cdaf0a7ad727b7bac9e4 100644 --- a/lib_dec/hf_synth.c +++ b/lib_dec/hf_synth.c @@ -63,6 +63,7 @@ static void envelope( AMRWB_IO_DEC_HANDLE hAmrwb_IO, const int32_t core_brate, c static void AdaptiveStartBand( int16_t *start_band, const int32_t core_brate, const float *lsf, const float voicing_fac, const int16_t clas, int16_t *voicing_flag, int16_t *start_band_old, float *OptCrit_old ); +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * hf_synth_init() * @@ -88,6 +89,8 @@ void hf_synth_init( return; } +#endif + /*-------------------------------------------------------------------* * hf_synth_amr_wb_init() * @@ -116,6 +119,7 @@ void hf_synth_amr_wb_init( return; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * hf_synth_amr_wb_reset() * @@ -476,7 +480,7 @@ void hf_synth_amr_wb( return; } - +#endif /*-----------------------------------------------------------------------------------* * hf_synthesis_amr_wb() * @@ -878,6 +882,7 @@ static void AdaptiveStartBand( } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * hf_synth_reset() * @@ -1067,6 +1072,7 @@ static void hf_synthesis( return; } +#endif /*-----------------------------------------------------------------------* * hp400_12k8() diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 011e0006edd581544df47c160f1d563e820d2e67..82b515c144c12e381c6dc74613c68654255174d7 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -61,6 +61,27 @@ void hf_synth_init_fx( return; } + +void hf_synth_reset_fx( + ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ +) +{ + Word16 i; + + FOR(i = 0; i < L_FRAME16k; i++) + { + Random(&hBWE_zero->seed2); + } + + set16_fx(hBWE_zero->mem_hf_fx, 0, ( L_FIR - 1 ) ); + set16_fx(hBWE_zero->mem_syn_hf_fx, 0, M); + set16_fx(hBWE_zero->mem_hp400_fx, 0, 6); + + set16_fx(hBWE_zero->delay_syn_hf_fx, 0, NS2SA(16000, DELAY_CLDFB_NS)); + set16_fx(hBWE_zero->mem_hp_interp_fx, 0, INTERP_3_1_MEM_LEN); + + return; +} #else void hf_synth_init_fx( ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ @@ -76,7 +97,6 @@ void hf_synth_init_fx( return; } -#endif void hf_synth_reset_fx( ZERO_BWE_DEC_HANDLE hBWE_zero /* o : zero BWE decoder handle */ ) @@ -97,6 +117,7 @@ void hf_synth_reset_fx( return; } +#endif /*---------------------------------------------------------------------* * hf_synth() diff --git a/lib_dec/hq_core_dec.c b/lib_dec/hq_core_dec.c index c3d58e470e2e495be4f543256d55e634a6eaafa5..58bf0673e532de55085f6822204f687d945ce7ff 100644 --- a/lib_dec/hq_core_dec.c +++ b/lib_dec/hq_core_dec.c @@ -54,7 +54,7 @@ * * HQ core decoder *--------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void hq_core_dec( Decoder_State *st, /* i/o: decoder state structure */ float synth[], /* o : output synthesis */ @@ -642,7 +642,7 @@ void hq_core_dec( pop_wmops(); return; } - +#endif /*-------------------------------------------------------------------* * hq_core_dec_init() diff --git a/lib_dec/hq_hr_dec.c b/lib_dec/hq_hr_dec.c index bd15037103c75c76029b59b349ebfc073abc27cc..4ecdfb91462b0734a935c23bc332cddacaf9bc8b 100644 --- a/lib_dec/hq_hr_dec.c +++ b/lib_dec/hq_hr_dec.c @@ -40,7 +40,7 @@ #include "rom_com.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*--------------------------------------------------------------------------* * hq_pred_hb_bws() * @@ -298,3 +298,4 @@ void hq_hr_dec( return; } +#endif diff --git a/lib_dec/hq_lr_dec.c b/lib_dec/hq_lr_dec.c index 1811a9baa87c293b54c16ebe7461144247ffef26..90b5d0f05e5462e98edfd254a87cb9c21fd5eb62 100644 --- a/lib_dec/hq_lr_dec.c +++ b/lib_dec/hq_lr_dec.c @@ -63,7 +63,7 @@ static void spt_shorten_domain_set_dec( Decoder_State *st, const int16_t p2a_fla * * HQ low rate decoding routine *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void hq_lr_dec( Decoder_State *st, /* i/o: decoder state structure */ float yout[], /* o : transform-domain output coefs. */ @@ -946,7 +946,7 @@ void hq_lr_dec( return; } - +#endif /*------------------------------------------------------------------------------------ * small_symbol_dec_tran() diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index d5bf467b1c9e6253a8c84397dabe1fed2f4ce55e..bbd3a88595a6111c9a02e18707cdc802cbd9be1d 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -915,7 +915,7 @@ ivas_error init_decoder_ivas_fx( mvr2r(GEWB_Ave, st_fx->mem_AR, M); set_f(st_fx->mem_MA, 0, M); - set_f(st_fx->dispMem, 0, 8); + //set_f(st_fx->dispMem, 0, 8); st_fx->tilt_code = 0.0f; st_fx->gc_threshold = 0.0f; } @@ -992,9 +992,9 @@ ivas_error init_decoder_ivas_fx( st_fx->stab_fac_smooth = 0.0f; set_f(st_fx->agc_mem2, 0, 2); set_f(st_fx->mem_syn3, 0, M); - st_fx->stab_fac_smooth_lt = 0.0f; - st_fx->log_energy_diff_lt = 0.0f; - st_fx->log_energy_old = 0.0f; + //st_fx->stab_fac_smooth_lt = 0.0f; + //st_fx->log_energy_diff_lt = 0.0f; + //st_fx->log_energy_old = 0.0f; // mvr2r(GEWB_Ave, st_fx->lsf_old, M); // lsf2lsp(st_fx->lsf_old, st_fx->lsp_old, M, INT_FS_12k8); @@ -1121,16 +1121,16 @@ ivas_error init_decoder_ivas_fx( if ( st_fx->ivas_format != ISM_FORMAT ) { st_fx->unv_cnt = 0; - st_fx->ge_sm = 10; + //st_fx->ge_sm = 10; st_fx->uv_count = 0; st_fx->act_count = 3; - mvr2r(st_fx->lsp_old, st_fx->lspold_s, M); + //mvr2r(st_fx->lsp_old, st_fx->lspold_s, M); st_fx->noimix_seed = RANDOM_INITSEED; - st_fx->exc_pe = 0; + //st_fx->exc_pe = 0; st_fx->prev_coder_type = GENERIC; - st_fx->tilt_wb = 0.0f; + //st_fx->tilt_wb = 0.0f; st_fx->last_voice_factor = 0.0f; set_f(st_fx->prev_synth_buffer, 0, NS2SA(48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS)); @@ -1138,7 +1138,7 @@ ivas_error init_decoder_ivas_fx( st_fx->old_bfi_cnt = 0; } #endif - st_fx->min_alpha = 1; + //st_fx->min_alpha = 1; st_fx->unv_cnt = 0; move16(); st_fx->ge_sm_fx = L_deposit_l(640); /*Q(GE_SHIFT)*/ @@ -1193,10 +1193,12 @@ ivas_error init_decoder_ivas_fx( return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n")); } #ifdef ISM_DISABLE // To be removed when fixed version is available. +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) if ( st_fx->ivas_format != ISM_FORMAT ) { GSC_dec_init_ivas(st_fx->hGSCDec); } +#endif #endif GSC_dec_init_ivas_fx(st_fx->hGSCDec); } @@ -1264,9 +1266,6 @@ ivas_error init_decoder_ivas_fx( return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for zero BWE\n")); } -#ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. - hf_synth_init(st_fx->hBWE_zero); -#endif hf_synth_init_fx(st_fx->hBWE_zero); } ELSE @@ -1465,7 +1464,7 @@ ivas_error init_decoder_ivas_fx( } #ifdef IVAS_FLOAT_FIXED_TO_BE_REMOVED // To be removed when fixed version is available. - fd_bwe_dec_init_flt(st_fx->hBWE_FD); + //fd_bwe_dec_init_flt(st_fx->hBWE_FD); #endif fd_bwe_dec_init(st_fx, st_fx->hBWE_FD); } @@ -1481,12 +1480,12 @@ ivas_error init_decoder_ivas_fx( #ifdef ISM_DISABLE // To be removed when fixed version is available. if ( st_fx->ivas_format != ISM_FORMAT ) { - st_fx->tilt_swb = 0.0f; - st_fx->prev_ener_shb = 0.0f; - st_fx->prev_enerLH = 0.0f; + //st_fx->tilt_swb = 0.0f; + //st_fx->prev_ener_shb = 0.0f; + //st_fx->prev_enerLH = 0.0f; st_fx->enerLH = 0.0f; st_fx->enerLL = 0.0f; - st_fx->prev_enerLL = 0.0f; + //st_fx->prev_enerLL = 0.0f; st_fx->prev_fractive = 0; st_fx->prev_bws_cnt = 0; st_fx->bws_cnt = N_WS2N_FRAMES; @@ -1577,12 +1576,6 @@ ivas_error init_decoder_ivas_fx( * channel-aware mode parameters *-----------------------------------------------------------------*/ -#ifdef ISM_DISABLE // To be removed when fixed version is available. - if ( st_fx->ivas_format != ISM_FORMAT ) - { - set_f(st_fx->tilt_code_dec, 0.0f, NB_SUBFR16k); - } -#endif set16_fx(st_fx->tilt_code_dec_fx, 0, NB_SUBFR16k); st_fx->use_partial_copy = 0; @@ -1701,14 +1694,6 @@ ivas_error init_decoder_ivas_fx( set16_fx(st_fx->flag_buffer, 0, 20); st_fx->avg_nrg_LT = 0; -#ifdef ISM_DISABLE // To be removed when fixed version is available. - if ( st_fx->ivas_format != ISM_FORMAT ) - { - st_fx->perc_bwddec_float = 0.0f; - st_fx->avg_nrg_LT_float = 0.0f; - } -#endif - /*-----------------------------------------------------------------* * Noise gate parameters *-----------------------------------------------------------------*/ @@ -1716,9 +1701,9 @@ ivas_error init_decoder_ivas_fx( #ifdef ISM_DISABLE // To be removed when fixed version is available. if ( st_fx->ivas_format != ISM_FORMAT ) { - st_fx->ng_ener_ST = -51.0f; + //st_fx->ng_ener_ST = -51.0f; - st_fx->old_Es_pred = 0; + //st_fx->old_Es_pred = 0; set_f(st_fx->old_Aq_12_8 + 1, 0, M); st_fx->old_Aq_12_8[0] = 1; } @@ -1766,8 +1751,8 @@ ivas_error init_decoder_ivas_fx( st_fx->ppp_mode_dec = 0; st_fx->last_nelp_mode_dec = 0; st_fx->nelp_mode_dec = 0; - st_fx->prev_gain_pit_dec = 0.0f; - st_fx->prev_tilt_code_dec = 0.0f; + //st_fx->prev_gain_pit_dec = 0.0f; + //st_fx->prev_tilt_code_dec = 0.0f; st_fx->vbr_hw_BWE_disable_dec = 0; st_fx->last_vbr_hw_BWE_disable_dec = 0; } diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index f330e7f649055cb5463c75c9ff8a8a4a475d25e8..5023a33ec56c044e9dcc9755955cdf4cdccf45d2 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -2101,8 +2101,10 @@ void ivas_binRenderer( #else //float reverbRe[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; //float reverbIm[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word64 reverbRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - Word64 reverbIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 reverbRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 reverbIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word64 reverbRe_fx_64[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word64 reverbIm_fx_64[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; //float inRe[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; //float inIm[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 inRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; @@ -2123,6 +2125,19 @@ void ivas_binRenderer( ivas_binaural_reverb_processSubframe_fx( hBinRenderer->hReverb, BINAURAL_CHANNELS, numTimeSlots, inRe_fx, inIm_fx, reverbRe_fx, reverbIm_fx ); // reverbRe_fx Q = exp_real_final - Q1 + Q30 = exp_real_final + Q29 + FOR(i = 0; i < BINAURAL_CHANNELS; i++) + { + FOR(j = 0; j < numTimeSlots; j++) + { + + FOR(k = 0; k < hBinRenderer->hReverb->numBins; k++) + { + reverbRe_fx_64[i][j][k] = W_shl(reverbRe_fx[i][j][k], Q30); + reverbIm_fx_64[i][j][k] = W_shl(reverbIm_fx[i][j][k], Q30); + } + } + } + /* Add the conv module and reverb module output */ FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index c827839717104eff80ae7228b44771f918e11288..8bad71ed25d59e6c9374157d69751176188e48c6 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -550,24 +550,13 @@ ivas_error ivas_core_dec( floatToFixed_arr32( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_32, Q_pst_old_syn, NBPSF_PIT_MAX ); st->hBPF->pst_mem_deemp_err_32 = float_to_fix( st->hBPF->pst_mem_deemp_err, Q_pst_mem_deemp_err ); } - IF( st->hBWE_zero ) - { - Q_mem_hf = Q_factor_arr( st->hBWE_zero->mem_hf, ( L_FIR - 1 ) ); - Q_mem_syn_hf = Q_factor_arr( st->hBWE_zero->mem_syn_hf, M ); - Q_mem_hp400 = Q_factor_arr( st->hBWE_zero->mem_hp400, 4 ); - Q_delay_syn_hf = Q_factor_arr( st->hBWE_zero->delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - Q_mem_hp_interp = Q_factor_arr( st->hBWE_zero->mem_hp_interp, INTERP_3_1_MEM_LEN ); - floatToFixed_arr16( st->hBWE_zero->mem_hf, st->hBWE_zero->mem_hf_fx, Q_mem_hf, ( L_FIR - 1 ) ); - floatToFixed_arr16( st->hBWE_zero->mem_syn_hf, st->hBWE_zero->mem_syn_hf_fx, Q_mem_syn_hf, M ); - floatToFixed_arr16( st->hBWE_zero->mem_hp400, st->hBWE_zero->mem_hp400_fx, Q_mem_hp400, 4 ); - floatToFixed_arr16( st->hBWE_zero->delay_syn_hf, st->hBWE_zero->delay_syn_hf_fx, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - floatToFixed_arr16( st->hBWE_zero->mem_hp_interp, st->hBWE_zero->mem_hp_interp_fx, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); - } +#if 0 IF( st->hBWE_FD ) { Q_old_syn_12k8_16k = Q_factor_arr( st->hBWE_FD->old_syn_12k8_16k, 36 ); floatToFixed_arr16( st->hBWE_FD->old_syn_12k8_16k, st->hBWE_FD->old_syn_12k8_16k_fx, Q_old_syn_12k8_16k, 36 ); } +#endif IF( st->hHQ_core ) { Q_prev_env = Q_factor_arrL( st->hHQ_core->prev_env, SFM_N_WB ); @@ -588,7 +577,7 @@ ivas_error ivas_core_dec( //floatToFixed_arr32( st->hHQ_core->last_ni_gain, st->hHQ_core->last_ni_gain_fx, 17, BANDS_MAX ); /*Q-17*/ //floatToFixed_arr16( st->hHQ_core->last_env, st->hHQ_core->last_env_fx, 1, BANDS_MAX ); /*Q-1*/ floatToFixed_arr32( st->hHQ_core->prev_coeff_out, st->hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); /*Q-12*/ - floatToFixed_arr16( st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, Q_syn_Overl, 960 ); + //floatToFixed_arr16( st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, Q_syn_Overl, 960 ); //st->hHQ_core->memfilt_lb_fx = float_to_fix16( st->hHQ_core->memfilt_lb, 0 ); //st->hHQ_core->mean_prev_hb_fx = float_to_fix( st->hHQ_core->mean_prev_hb, 0 ); //st->hHQ_core->smoothmem_fx = float_to_fix16( st->hHQ_core->smoothmem, 15 ); @@ -634,8 +623,6 @@ ivas_error ivas_core_dec( //floatToFixed_arr16( st->old_exc, st->old_exc_fx, Q_old_exc, 480 ); floatToFixed_arr32( st->previoussynth, st->previoussynth_fx_32, 0, 960 ); st->enr_old_fx = (Word32) st->enr_old; - st->log_energy_diff_lt_fx = float_to_fix( st->log_energy_diff_lt, Q15 ); - st->stab_fac_smooth_lt_fx = float_to_fix16( st->stab_fac_smooth_lt, Q15 ); st->lp_ener_fx = float_to_fix( st->lp_ener, Q6 ); st->lp_gainc_fx = (Word16) L_min( 32767, float_to_fix( st->lp_gainc, 3 ) ); //floatToFixed_arr16( st->mem_syn_r_float, st->mem_syn_r, Q_mem_syn, L_SYN_MEM ); @@ -675,16 +662,9 @@ ivas_error ivas_core_dec( { fixedToFloat_arr( st->hTcxDec->old_syn_Overl, st->hTcxDec->old_syn_Overl_float, Q_old_syn_Overl, L_FRAME32k / 2 ); } - IF( st->hBWE_FD ) - fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); - IF( st->hBWE_zero ) - { - fixedToFloat_arr( st->hBWE_zero->mem_hf_fx, st->hBWE_zero->mem_hf, Q_mem_hf, ( L_FIR - 1 ) ); - fixedToFloat_arr( st->hBWE_zero->mem_syn_hf_fx, st->hBWE_zero->mem_syn_hf, Q_mem_syn_hf, M ); - fixedToFloat_arr( st->hBWE_zero->mem_hp400_fx, st->hBWE_zero->mem_hp400, Q_mem_hp400, 4 ); - fixedToFloat_arr( st->hBWE_zero->delay_syn_hf_fx, st->hBWE_zero->delay_syn_hf, Q_delay_syn_hf, NS2SA( 16000, DELAY_CLDFB_NS ) ); - fixedToFloat_arr( st->hBWE_zero->mem_hp_interp_fx, st->hBWE_zero->mem_hp_interp, Q_mem_hp_interp, INTERP_3_1_MEM_LEN ); - } + //IF( st->hBWE_FD ) + //fixedToFloat_arr( st->hBWE_FD->old_syn_12k8_16k_fx, st->hBWE_FD->old_syn_12k8_16k, Q_old_syn_12k8_16k, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); + IF( st->cldfbAna ) fixedToFloat_arrL( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_state, Q10, st->cldfbAna->cldfb_state_length ); IF( st->cldfbSyn ) @@ -704,7 +684,7 @@ ivas_error ivas_core_dec( //st->hHQ_core->mean_prev = fixedToFloat( st->hHQ_core->mean_prev_fx, 0 ); //st->hHQ_core->mean_prev_nc = fixedToFloat( st->hHQ_core->mean_prev_nc_fx, 0 ); //st->hHQ_core->wmold_hb = st->hHQ_core->wmold_hb_fx / 32767.f; - fixedToFloat_arr( st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, Q_syn_Overl, 960 ); + //fixedToFloat_arr( st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, Q_syn_Overl, 960 ); } IF( st->hFdCngDec ) { @@ -830,34 +810,34 @@ ivas_error ivas_core_dec( floatToFixed_arr( st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1, L_FRAME32k / 2 ); floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); floatToFixed_arrL( hHQ_core->prev_coeff_out, hHQ_core->prev_coeff_out_fx, Q12, L_HQ_WB_BWE ); - FOR( i = 0; i < 3; ++i ) - { - hHQ_core->old_is_transient[i] = hHQ_core->old_is_transient[i]; - } - hHQ_core->HqVoicing = hHQ_core->HqVoicing; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas; - hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed; - FOR( i = 0; i < SFM_N_ENV_STAB; ++i ) - { - hHQ_core->mem_norm[i] = hHQ_core->mem_norm[i]; - hHQ_core->mem_norm_hqfec[i] = hHQ_core->mem_norm_hqfec[i]; - } - hHQ_core->mem_env_delta = hHQ_core->mem_env_delta; - hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec; - hHQ_core->no_att_hangover = hHQ_core->no_att_hangover; - hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing; - hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt; + //FOR( i = 0; i < 3; ++i ) + //{ + // hHQ_core->old_is_transient[i] = hHQ_core->old_is_transient[i]; + //} + //hHQ_core->HqVoicing = hHQ_core->HqVoicing; + //hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; + //hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas; + //hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed; + //FOR( i = 0; i < SFM_N_ENV_STAB; ++i ) + //{ + // hHQ_core->mem_norm[i] = hHQ_core->mem_norm[i]; + // hHQ_core->mem_norm_hqfec[i] = hHQ_core->mem_norm_hqfec[i]; + //} + //hHQ_core->mem_env_delta = hHQ_core->mem_env_delta; + //hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec; + //hHQ_core->no_att_hangover = hHQ_core->no_att_hangover; + //hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing; + //hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt; floatToFixed_arr( st->hTcxDec->prev_good_synth - tmp_size, st->hTcxDec->prev_good_synth_fx - tmp_size, 0, 2 * output_frame + tmp_size ); - hHQ_core->time_offs = hHQ_core->time_offs; - hHQ_core->num_p = hHQ_core->num_p; - FOR( i = 0; i < MAX_PLOCS; ++i ) - { - hHQ_core->plocs[i] = hHQ_core->plocs[i]; - } - hHQ_core->last_fec = hHQ_core->last_fec; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active; + //hHQ_core->time_offs = hHQ_core->time_offs; + //hHQ_core->num_p = hHQ_core->num_p; + //FOR( i = 0; i < MAX_PLOCS; ++i ) + //{ + // hHQ_core->plocs[i] = hHQ_core->plocs[i]; + //} + //hHQ_core->last_fec = hHQ_core->last_fec; + //hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; + //hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active; #endif ivas_hq_core_dec_fx( st, synth_fx, &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_fx, &Q_output ); @@ -875,32 +855,32 @@ ivas_error ivas_core_dec( { hHQ_core->prev_coeff_out[i] = hHQ_core->old_is_transient[i]; } - hHQ_core->HqVoicing = hHQ_core->HqVoicing; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas; - hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed; - FOR( i = 0; i < SFM_N_ENV_STAB; ++i ) + //hHQ_core->HqVoicing = hHQ_core->HqVoicing; + //hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; + //hHQ_core->prev_hqswb_clas = hHQ_core->prev_hqswb_clas; + //hHQ_core->hq_generic_seed = hHQ_core->hq_generic_seed; + /*FOR( i = 0; i < SFM_N_ENV_STAB; ++i ) { hHQ_core->mem_norm[i] = hHQ_core->mem_norm[i]; hHQ_core->mem_norm_hqfec[i] = hHQ_core->mem_norm_hqfec[i]; - } - hHQ_core->mem_env_delta = hHQ_core->mem_env_delta; - hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec; - hHQ_core->no_att_hangover = hHQ_core->no_att_hangover; - hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing; - hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt; + }*/ + //hHQ_core->mem_env_delta = hHQ_core->mem_env_delta; + //hHQ_core->mem_env_delta_hqfec = hHQ_core->mem_env_delta_hqfec; + //hHQ_core->no_att_hangover = hHQ_core->no_att_hangover; + //hHQ_core->oldHqVoicing = hHQ_core->oldHqVoicing; + //hHQ_core->envstabplc_hocnt = hHQ_core->envstabplc_hocnt; fixedToFloat_arr( st->hTcxDec->prev_good_synth_fx - tmp_size, st->hTcxDec->prev_good_synth - tmp_size, 0, 2 * output_frame + tmp_size ); - hHQ_core->time_offs = hHQ_core->time_offs; - hHQ_core->num_p = hHQ_core->num_p; - FOR( i = 0; i < MAX_PLOCS; ++i ) + //hHQ_core->time_offs = hHQ_core->time_offs; + //hHQ_core->num_p = hHQ_core->num_p; + /*FOR( i = 0; i < MAX_PLOCS; ++i ) { hHQ_core->plocs[i] = hHQ_core->plocs[i]; - } + }*/ //fixedToFloat_arrL( hHQ_core->plocsi_fx, hHQ_core->plocsi, Q16, MAX_PLOCS ); //hHQ_core->env_stab = fixedToFloat( hHQ_core->env_stab_fx, Q15 ); - hHQ_core->last_fec = hHQ_core->last_fec; - hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; - hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active; + //hHQ_core->last_fec = hHQ_core->last_fec; + //hHQ_core->ph_ecu_HqVoicing = hHQ_core->ph_ecu_HqVoicing; + //hHQ_core->ph_ecu_active = hHQ_core->ph_ecu_active; #endif #else hq_core_dec( st, synth[n], output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output[n] ); @@ -1260,14 +1240,14 @@ ivas_error ivas_core_dec( Word16 delay_comp = i_mult2(delta, HQ_DELAY_COMP); - if (st->hBWE_FD != NULL) - { - st->hBWE_FD->mem_deemph_old_syn_fx = (Word16)floatToFixed(st->hBWE_FD->mem_deemph_old_syn, 0); - } + //if (st->hBWE_FD != NULL) + //{ + // st->hBWE_FD->mem_deemph_old_syn_fx = (Word16)floatToFixed(st->hBWE_FD->mem_deemph_old_syn, 0); + //} IF(st->hHQ_core != NULL) { floatToFixed_arr(st->hHQ_core->old_out, st->hHQ_core->old_out_fx, 0, L_FRAME48k); - floatToFixed_arr(st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, 0, NS2SA(st->output_Fs, 3000000)); + //floatToFixed_arr(st->hHQ_core->fer_samples, st->hHQ_core->fer_samples_fx, 0, 960); //FOR(i = 0; i < SFM_N_WB; ++i) //{ // st->hHQ_core->prev_env_fx[i] = floatToFixed(st->hHQ_core->prev_env[i], st->hHQ_core->prev_env_Q[i]); @@ -1448,7 +1428,7 @@ ivas_error ivas_core_dec( IF(st->hHQ_core != NULL) { fixedToFloat_arr(st->hHQ_core->old_out_fx, st->hHQ_core->old_out, 0, L_FRAME48k); - fixedToFloat_arr(st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, 0, NS2SA(st->output_Fs, 3000000)); + //fixedToFloat_arr(st->hHQ_core->fer_samples_fx, st->hHQ_core->fer_samples, 0, 960); //FOR(i = 0; i < SFM_N_WB; ++i) //{ // st->hHQ_core->prev_env[i] = fixedToFloat(st->hHQ_core->prev_env_fx[i], st->hHQ_core->prev_env_Q[i]); @@ -1466,22 +1446,24 @@ ivas_error ivas_core_dec( Word8 reset_swb_tbe = 0; Word8 reset_swb_tbe_synth = 0; +#if 0 if (st->hBWE_FD != NULL) { st->hBWE_FD->mem_deemph_old_syn = fixedToFloat(st->hBWE_FD->mem_deemph_old_syn_fx, 0); } +#endif IF((NE_16(st->last_extl, SWB_BWE) && EQ_16(st->extl, SWB_BWE)) || (NE_16(st->last_extl, FB_BWE) && EQ_16(st->extl, FB_BWE)) || ((EQ_16(st->last_core, HQ_CORE) || EQ_16(st->last_extl, SWB_TBE)) && st->extl < 0 && NE_16(st->core, HQ_CORE)) || (EQ_16(st->last_core, ACELP_CORE) && EQ_16(st->core, ACELP_CORE) && ((NE_16(st->prev_coder_type, INACTIVE) && EQ_16(st->coder_type, INACTIVE)) || (NE_16(st->prev_coder_type, AUDIO) && EQ_16(st->coder_type, AUDIO))) && st->bws_cnt > 0)) { - fixedToFloat_arr(st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, 0, output_frame); + //fixedToFloat_arr(st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, 0, output_frame); - st->hBWE_FD->prev_Energy = fixedToFloat(st->hBWE_FD->prev_Energy_fx, 0); // setting to zero - st->hBWE_FD->prev_frica_flag = st->hBWE_FD->prev_frica_flag; // fixed - st->hBWE_FD->prev_td_energy = st->hBWE_FD->prev_td_energy_fx; // setting to zero - st->hBWE_FD->prev_weight = fixedToFloat(st->hBWE_FD->prev_weight_fx, 15); // 6554; /*0.2 in Q15*/ - st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(st->prev_fb_ener_adjust_fx, 0); // setting to zero - fixedToFloat_arr(st->hBWE_FD->mem_imdct_fx, st->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero + //st->hBWE_FD->prev_Energy = fixedToFloat(st->hBWE_FD->prev_Energy_fx, 0); // setting to zero + //st->hBWE_FD->prev_frica_flag = st->hBWE_FD->prev_frica_flag; // fixed + //st->hBWE_FD->prev_td_energy = st->hBWE_FD->prev_td_energy_fx; // setting to zero + //st->hBWE_FD->prev_weight = fixedToFloat(st->hBWE_FD->prev_weight_fx, 15); // 6554; /*0.2 in Q15*/ + //st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(st->prev_fb_ener_adjust_fx, 0); // setting to zero + //fixedToFloat_arr(st->hBWE_FD->mem_imdct_fx, st->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero } /* reset WB BWE buffers */ @@ -1489,16 +1471,16 @@ ivas_error ivas_core_dec( IF(NE_16(st->last_extl, WB_BWE) && EQ_16(st->extl, WB_BWE) && st->hBWE_FD != NULL) { // set16_fx( st->hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); - fixedToFloat_arr(st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, 0, output_frame); + //fixedToFloat_arr(st->hBWE_FD->L_old_wtda_swb_fx, st->hBWE_FD->old_wtda_swb, 0, output_frame); IF(NE_16(st->last_extl, SWB_BWE) && NE_16(st->last_extl, FB_BWE)) { st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; } - st->hBWE_FD->prev_Energy_wb = (float)st->hBWE_FD->prev_Energy_wb_fx; + //st->hBWE_FD->prev_Energy_wb = (float)st->hBWE_FD->prev_Energy_wb_fx; st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; - fixedToFloat_arr(st->hBWE_FD->mem_imdct_fx, st->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero + //fixedToFloat_arr(st->hBWE_FD->mem_imdct_fx, st->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero } /* reset TBE buffers */ @@ -1537,10 +1519,12 @@ ivas_error ivas_core_dec( IF(EQ_16(st->bwidth, FB)) { +#if 0 IF(st->hBWE_FD != NULL) { st->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(st->prev_fb_ener_adjust_fx, 0); } +#endif fixedToFloat_arr(st->hBWE_TD->fb_state_lpc_syn_fx, st->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); } } @@ -1628,13 +1612,12 @@ ivas_error ivas_core_dec( FD_BWE_DEC_HANDLE hBWE_FD; hBWE_FD = st->hBWE_FD; - st->prev_tilt_code_dec_fx = (Word16) floatToFixed( st->prev_tilt_code_dec, Q15 ); floatToFixed_arr( voice_factors[n], voice_factors_fx[n], Q15, NB_SUBFR16k ); floatToFixed_arr( pitch_buf[n], pitch_buf_fx[n], Q6, NB_SUBFR16k ); st->cummulative_damping = float_to_fix16( st->cummulative_damping_float, Q15 ); - st->prev_ener_shb_fx = float_to_fix16( st->prev_ener_shb, 1 ); + //st->prev_ener_shb_fx = float_to_fix16( st->prev_ener_shb, 1 ); st->enerLH_fx = floatToFixed( st->enerLH, 0 ); // Check if Q_syn2 - st->prev_enerLH_fx = floatToFixed( st->prev_enerLH, 0 ); // Check if Q_syn2 + //st->prev_enerLH_fx = floatToFixed( st->prev_enerLH, 0 ); // Check if Q_syn2 floatToFixed_arrL( old_syn_12k8_16k[n], old_syn_12k8_16k_fx, Q11, L_FRAME16k ); // Can be removed got from last fn @@ -1679,6 +1662,7 @@ ivas_error ivas_core_dec( } } +#if 0 IF( hBWE_FD != NULL ) { st->last_wb_bwe_ener_fx = (Word16) floatToFixed( hBWE_FD->last_wb_bwe_ener, Q3 ); @@ -1692,6 +1676,7 @@ ivas_error ivas_core_dec( hBWE_FD->prev_Energy_wb_fx = floatToFixed( hBWE_FD->prev_Energy_wb, st->prev_Q_synth ); } +#endif IF( st->hTdCngDec != NULL ) { @@ -1840,32 +1825,30 @@ ivas_error ivas_core_dec( #ifdef IVAS_FLOAT_FIXED Word16 synth_fx[960], hb_synth_fx[960]; /* Q-2 */ Word16 q = 2; - st->prev_Q_bwe_syn2 = 0; + //st->prev_Q_bwe_syn2 = 0; Copy_Scale_sig_32_16(hb_synth_fx32, hb_synth_fx, L_FRAME48k, -(Q11 + q)); Copy_Scale_sig_32_16(synth_fx32, synth_fx, L_FRAME48k, -(Q11 + q)); Scale_sig(st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, (Q8 - st->prev_Q_bwe_syn)); - Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -Q11); - Copy_Scale_sig_32_16(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, -Q11); + Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, (st->prev_Q_bwe_syn2 - Q11)); + Copy_Scale_sig_32_16(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, (st->prev_Q_bwe_syn2 - Q11)); swb_CNG_dec_ivas_fx( st, synth_fx, hb_synth_fx, sid_bw[n], -q ); Copy_Scale_sig_16_32(hb_synth_fx, hb_synth_fx32, L_FRAME48k, (Q11 + q)); Copy_Scale_sig_16_32(synth_fx, synth_fx32, L_FRAME48k, (Q11 + q)); Scale_sig(st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -(Q8 - st->prev_Q_bwe_syn)); - Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, Q11); - Copy_Scale_sig_16_32(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, Q11); + Scale_sig32(st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -(st->prev_Q_bwe_syn2 - Q11)); + Copy_Scale_sig_16_32(st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -(st->prev_Q_bwe_syn2 - Q11)); #endif } #ifndef IVAS_FLOAT_CONV_TO_BE_REMOVED - st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); fixedToFloat_arr(voice_factors_fx[n], voice_factors[n], Q15, NB_SUBFR16k); fixedToFloat_arr(pitch_buf_fx[n], pitch_buf[n], Q6, NB_SUBFR16k); - st->prev_ener_shb = (float)st->prev_ener_shb_fx / 2; st->cummulative_damping_float = fixedToFloat(st->cummulative_damping, Q15); - st->prev_ener_shb = fixedToFloat(st->prev_ener_shb_fx, 1); + //st->prev_ener_shb = fixedToFloat(st->prev_ener_shb_fx, 1); st->enerLH = fixedToFloat(st->enerLH_fx, 0); // Check if Q_syn2 - st->prev_enerLH = fixedToFloat(st->prev_enerLH_fx, 0); // Check if Q_syn2 + //st->prev_enerLH = fixedToFloat(st->prev_enerLH_fx, 0); // Check if Q_syn2 fixedToFloat_arrL(bwe_exc_extended_fx[n], bwe_exc_extended[n], 2 * st->Q_exc, L_FRAME32k + NL_BUFF_OFFSET); @@ -1919,6 +1902,7 @@ ivas_error ivas_core_dec( IF(hBWE_FD != NULL) { +#if 0 hBWE_FD->last_wb_bwe_ener = fixedToFloat(st->last_wb_bwe_ener_fx, Q3); fixedToFloat_arr(st->prev_SWB_fenv_fx, hBWE_FD->prev_SWB_fenv, Q1, SWB_FENV); fixedToFloat_arr(hBWE_FD->mem_imdct_fx, hBWE_FD->mem_imdct, hBWE_FD->mem_imdct_exp_fx, L_FRAME48k); @@ -1928,9 +1912,10 @@ ivas_error ivas_core_dec( st->hBWE_FD->prev_td_energy = (float)st->hBWE_FD->prev_td_energy_fx; hBWE_FD->prev_Energy_wb = fixedToFloat(hBWE_FD->prev_Energy_wb_fx, st->prev_Q_synth); +#endif // Check - fixedToFloat_arrL(hBWE_FD->L_old_wtda_swb_fx32, hBWE_FD->old_wtda_swb, Q11, L_FRAME48k); + //fixedToFloat_arrL(hBWE_FD->L_old_wtda_swb_fx32, hBWE_FD->old_wtda_swb, Q11, L_FRAME48k); } IF(st->hTdCngDec != NULL) @@ -2342,7 +2327,6 @@ ivas_error ivas_core_dec( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); } @@ -2357,7 +2341,6 @@ ivas_error ivas_core_dec( { hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); } - hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); } IF(hCPE->hCoreCoder[ch_ind]->hTcxDec != NULL) @@ -2405,7 +2388,6 @@ ivas_error ivas_core_dec( { hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] * (1u << OUTPUT_Q)); } - hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain = (Word16)(hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); } } @@ -2413,12 +2395,11 @@ ivas_error ivas_core_dec( Word16 exp_max = 0; Word32 output_fx_loc[L_FRAME48k]; - floatToFixed_arr(st->old_synth_sw, st->old_synth_sw_fx, -2, 429); - st->prev_tilt_code_dec_fx = (Word16)floatToFixed(st->prev_tilt_code_dec, Q15); + //floatToFixed_arr(st->old_synth_sw, st->old_synth_sw_fx, -2, 429); FOR(Word16 ind = 0; ind < 16; ind++) { st->mem_AR_fx[ind] = (Word16)(st->mem_AR[ind] * 2.56f); } - fixedToFloat_arr(st->old_synth_sw_fx, st->old_synth_sw, 0, 429); + //fixedToFloat_arr(st->old_synth_sw_fx, st->old_synth_sw, 0, 429); #endif IF ( NE_16(st->element_mode, IVAS_CPE_DFT )) @@ -2561,7 +2542,6 @@ ivas_error ivas_core_dec( { hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); } - hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hCoreCoder[ch_ind]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } IF(hCPE->hCoreCoder[ch_ind]->hTcxDec != NULL) @@ -2619,7 +2599,6 @@ ivas_error ivas_core_dec( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } @@ -2662,7 +2641,6 @@ ivas_error ivas_core_dec( { hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] / (1u << OUTPUT_Q); } - hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float = (float)hSCE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } @@ -2676,11 +2654,10 @@ ivas_error ivas_core_dec( } } - fixedToFloat_arr(st->old_synth_sw_fx, st->old_synth_sw, -2, 429); + //fixedToFloat_arr(st->old_synth_sw_fx, st->old_synth_sw, -2, 429); FOR(Word16 ind = 0; ind < 16; ind++) { st->mem_AR[ind] = st->mem_AR_fx[ind] / 2.56f; } - st->prev_tilt_code_dec = fixedToFloat(st->prev_tilt_code_dec_fx, Q15); #endif } /* n_channels loop */ diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 8f8c7fee151f4ce0421d14a4232fd7a45fdc31ed..985d893e69d07ed90678000297959fa6ffdde2fb 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -140,7 +140,7 @@ ivas_error ivas_cpe_dec_fx( #else #if 1 // Float to fix conversions float maxim = 0; - Word16 q_output_mem, q_buff_LBTCX_mem, q_input_mem_LB, q_old_out = 31, q_old_out_LB = 31, q_tcxltp_mem_in_float=15, q_tcxltp_gain_post_prev = 15; + Word16 q_output_mem, q_buff_LBTCX_mem, q_input_mem_LB, q_old_out = 31, q_old_out_LB = 31, q_tcxltp_mem_in_float=15; q_output_mem = 11; IF(hCPE->hStereoDft) FOR(Word16 ind1 = 0; ind1 < 2; ind1++) { @@ -201,10 +201,6 @@ ivas_error ivas_cpe_dec_fx( FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[ind] = (Word32)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[ind] * (1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) { - IF(fabsf(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float) > 1) assert(0);//q_tcxltp_gain_post_prev = norm_s(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev); - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * (1 << q_tcxltp_gain_post_prev)); - } FOR(Word16 ind2 = 0; ind2 < 2; ind2++) { IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) FOR(Word16 ind = 0; ind < s_min(12, (Word16)(TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs) / 48000); ind++) { @@ -214,10 +210,6 @@ ivas_error ivas_cpe_dec_fx( FOR(Word16 ind = 0; ind < s_min(12, (Word16)(L_FRAME48k * st_ivas->hDecoderConfig->output_Fs) / 48000); ind++) { hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_32[ind] = (Word32)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_float[ind] * (1 << q_tcxltp_mem_in_float)); } - IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) { - IF(fabsf(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float) > 1) assert(0);//q_tcxltp_gain_post_prev = norm_s(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float); - hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float * (1 << q_tcxltp_gain_post_prev)); - } IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->cldfbSyn) hCPE->hCoreCoder[ind2]->cldfbSyn->scale = (Word16)(hCPE->hCoreCoder[ind2]->cldfbSyn->scale_flt * (1u << norm_s((Word16)hCPE->hCoreCoder[0]->cldfbSyn->scale_flt))); } @@ -275,8 +267,6 @@ ivas_error ivas_cpe_dec_fx( FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[ind] = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[ind] / (float)(1<hStereoDft && hCPE->hStereoDft->hTcxLtpDec) - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / (float)(1 << q_tcxltp_gain_post_prev); FOR(Word16 ind2 = 0; ind2 < 2; ind2++) { IF(hCPE->hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) FOR(Word16 ind = 0; ind < s_min(12, (Word16)( TCXLTP_MAX_DELAY * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { @@ -286,8 +276,6 @@ ivas_error ivas_cpe_dec_fx( FOR(Word16 ind = 0; ind < s_min(12, (Word16)( L_FRAME48k * st_ivas->hDecoderConfig->output_Fs ) / 48000) ; ind++) { hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_float[ind] = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_mem_out_32[ind] / (float)(1<hCoreCoder[ind2] && hCPE->hCoreCoder[ind2]->hTcxLtpDec) - hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[ind2]->hTcxLtpDec->tcxltp_gain_post_prev / (float)(1 << q_tcxltp_gain_post_prev); } IF(hCPE->hStereoMdct) hCPE->hStereoMdct->smooth_ratio = hCPE->hStereoMdct->smooth_ratio_fx / (float)(ONE_IN_Q26); @@ -725,9 +713,9 @@ ivas_error ivas_cpe_dec_fx( Word32 output_fix[L_FRAME8k]; hCPE->hStereoDft->q_res_cod_mem_fx = 0; // keeping same as shift needed inside. floatToFixed_arrL(hCPE->hStereoDft->res_cod_mem, hCPE->hStereoDft->res_cod_mem_fx, Q16, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); - floatToFixed_arr(hCPE->hStereoDft->hBpf->pst_old_syn, hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx) / sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx[0])); - floatToFixed_arr(hCPE->hStereoDft->hBpf->mem_mean_pit, hCPE->hStereoDft->hBpf->mem_mean_pit_fx, Q4, sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit) / sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit[0])); - floatToFixed_arr(hCPE->hCoreCoder[0]->old_pitch_buf, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, Q6, sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx) / sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx[0])); + //floatToFixed_arr(hCPE->hStereoDft->hBpf->pst_old_syn, hCPE->hStereoDft->hBpf->pst_old_syn_fx, 0, sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx) / sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx[0])); + //floatToFixed_arr(hCPE->hStereoDft->hBpf->mem_mean_pit, hCPE->hStereoDft->hBpf->mem_mean_pit_fx, Q4, sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit) / sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit[0])); + //floatToFixed_arr(hCPE->hCoreCoder[0]->old_pitch_buf, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, Q6, sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx) / sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx[0])); hCPE->hStereoDft->hBpf->psf_att_fx = (Word16)floatToFixed(hCPE->hStereoDft->hBpf->psf_att, Q15); hCPE->hStereoDft->stab_fac_smooth_res_fx = (Word16)floatToFixed(hCPE->hStereoDft->stab_fac_smooth_res, Q15); @@ -735,9 +723,9 @@ ivas_error ivas_cpe_dec_fx( hCPE->hStereoDft->stab_fac_smooth_res = fixedToFloat(hCPE->hStereoDft->stab_fac_smooth_res_fx, Q15); hCPE->hStereoDft->hBpf->psf_att = fixedToFloat(hCPE->hStereoDft->hBpf->psf_att_fx, Q15); - fixedToFloat_arr(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf, Q6, sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx) / sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx[0])); - fixedToFloat_arr(hCPE->hStereoDft->hBpf->mem_mean_pit_fx, hCPE->hStereoDft->hBpf->mem_mean_pit, Q4, sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit) / sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit[0])); - fixedToFloat_arr(hCPE->hStereoDft->hBpf->pst_old_syn_fx, hCPE->hStereoDft->hBpf->pst_old_syn, 0, sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx) / sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx[0])); + //fixedToFloat_arr(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf, Q6, sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx) / sizeof(hCPE->hCoreCoder[0]->old_pitch_buf_16_fx[0])); + //fixedToFloat_arr(hCPE->hStereoDft->hBpf->mem_mean_pit_fx, hCPE->hStereoDft->hBpf->mem_mean_pit, Q4, sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit) / sizeof(hCPE->hStereoDft->hBpf->mem_mean_pit[0])); + //fixedToFloat_arr(hCPE->hStereoDft->hBpf->pst_old_syn_fx, hCPE->hStereoDft->hBpf->pst_old_syn, 0, sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx) / sizeof(hCPE->hStereoDft->hBpf->pst_old_syn_fx[0])); fixedToFloat_arrL(hCPE->hStereoDft->res_cod_mem_fx, hCPE->hStereoDft->res_cod_mem, Q16, sizeof(hCPE->hStereoDft->res_cod_mem_fx) / sizeof(hCPE->hStereoDft->res_cod_mem_fx[0])); fixedToFloat_arrL(&output_fix[0], output_flt[1], Q15, L_FRAME8k); } @@ -747,7 +735,76 @@ ivas_error ivas_cpe_dec_fx( } /* DFT stereo CNG */ +#ifndef IVAS_FLOAT_FIXED stereo_dtf_cng( hCPE, ivas_total_brate, DFT, output_frame ); +#else + { + Word16 q_dft, q_smoothed_psd; + float max_val = 0.0; + int i_max_val =0, i_max_val_psd = 0; + for (int ii = 0; ii < sizeof(DFT) / sizeof(DFT[0]); ii++) + { + for (int jj = 0; jj < sizeof(DFT[0]) / sizeof(DFT[0][0]); jj++) + { + if (max_val < fabs(DFT[ii][jj])) + { + max_val = (float)fabs(DFT[ii][jj]); + } + } + } + max_val = 0.0; + for (int ii = 0; ii < sizeof(sts[0]->hFdCngDec->smoothed_psd) / sizeof(sts[0]->hFdCngDec->smoothed_psd[0]); ii++) + { + if (max_val < fabs(sts[0]->hFdCngDec->smoothed_psd[ii])) + { + max_val = (float)fabs(sts[0]->hFdCngDec->smoothed_psd[ii]); + } + } + i_max_val_psd = (int)max_val; + sts[0]->hFdCngDec->q_smoothed_psd = norm_l(i_max_val_psd) - Q4; + i_max_val = (int)max_val; + q_dft = s_min(Q8, norm_l(i_max_val)); + //hCPE->hStereoDft->q_dft = norm_l(i_max_val); + //IF (hCPE->hStereoDft->q_dft > Q8) + //{ + // hCPE->hStereoDft->q_dft = Q8; + //} + floatToFixed_arrL(sts[0]->hFdCngDec->bandNoiseShape_float, sts[0]->hFdCngDec->bandNoiseShape, Q31 - sts[0]->hFdCngDec->bandNoiseShape_exp, FFTLEN2); + floatToFixed_arrL(&DFT[0][0], &DFT_fx[0][0], q_dft, sizeof(DFT) / sizeof(DFT[0][0])); + //floatToFixed_arr(&hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0], &hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx[0], Q15, sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx) / sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx[0])); + floatToFixed_arr(&hCPE->hStereoCng->cm[0], &hCPE->hStereoCng->cm_fx[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); + floatToFixed_arr(&hCPE->hStereoCng->coh[0], &hCPE->hStereoCng->coh_fx[0], Q15, sizeof(hCPE->hStereoCng->coh_fx) / sizeof(hCPE->hStereoCng->coh_fx[0]) ); + floatToFixed_arr(&hCPE->hStereoDft->g_state[0], &hCPE->hStereoDft->g_state_fx[0], Q15, sizeof(hCPE->hStereoDft->g_state_fx) / sizeof(hCPE->hStereoDft->g_state_fx[0])); + floatToFixed_arrL(&sts[0]->hFdCngDec->smoothed_psd[0], &sts[0]->hFdCngDec->smoothed_psd_fx[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel = s_max(0, Q31 - hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp); + floatToFixed_arrL(&hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[0], + &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel[0], + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel, + FFTCLDFBLEN); + //sts[0]->lp_noise = floatToFixed(sts[0]->lp_noise_float, Q23); + hCPE->hCoreCoder[0]->hFdCngDec->lp_noise = floatToFixed(hCPE->hCoreCoder[0]->hFdCngDec->lp_noise_float, Q23); + hCPE->hCoreCoder[0]->hFdCngDec->lp_speech = floatToFixed(hCPE->hCoreCoder[0]->hFdCngDec->lp_speech_float, Q23); + floatToFixed_arrL(&hCPE->hStereoDft->side_gain[0], &hCPE->hStereoDft->side_gain_fx[0], 31, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX); + + stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft); + + fixedToFloat_arrL(&hCPE->hStereoDft->side_gain_fx[0], &hCPE->hStereoDft->side_gain[0], 31, STEREO_DFT_DEC_DFT_NB * STEREO_DFT_BAND_MAX); + hCPE->hCoreCoder[0]->hFdCngDec->lp_speech_float = fixedToFloat(hCPE->hCoreCoder[0]->hFdCngDec->lp_speech, Q23); + hCPE->hCoreCoder[0]->hFdCngDec->lp_noise_float = fixedToFloat(hCPE->hCoreCoder[0]->hFdCngDec->lp_noise, Q23); + //sts[0]->lp_noise_float = fixedToFloat(sts[0]->lp_noise, Q23); + fixedToFloat_arrL(&hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel[0], + &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[0], + hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->q_cngNoiseLevel, + FFTCLDFBLEN); + fixedToFloat_arrL(&sts[0]->hFdCngDec->smoothed_psd_fx[0], &sts[0]->hFdCngDec->smoothed_psd[0], sts[0]->hFdCngDec->q_smoothed_psd, sizeof(sts[0]->hFdCngDec->smoothed_psd_fx) / sizeof(sts[0]->hFdCngDec->smoothed_psd_fx[0])); + fixedToFloat_arr(&hCPE->hStereoDft->g_state_fx[0], &hCPE->hStereoDft->g_state[0], Q15, sizeof(hCPE->hStereoDft->g_state_fx) / sizeof(hCPE->hStereoDft->g_state_fx[0])); + fixedToFloat_arr(&hCPE->hStereoCng->coh_fx[0], &hCPE->hStereoCng->coh[0], Q15, sizeof(hCPE->hStereoCng->coh_fx) / sizeof(hCPE->hStereoCng->coh_fx[0]) ); + fixedToFloat_arr( &hCPE->hStereoCng->cm_fx[0], &hCPE->hStereoCng->cm[0], Q15, sizeof( hCPE->hStereoCng->cm_fx ) / sizeof( hCPE->hStereoCng->cm_fx[0] ) ); + //fixedToFloat_arr(&hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG_fx[0], &hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0], Q15, sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG) / sizeof(hCPE->hCoreCoder[0]->hTdCngDec->shb_lpcCNG[0])); + fixedToFloat_arrL(sts[0]->hFdCngDec->bandNoiseShape, sts[0]->hFdCngDec->bandNoiseShape_float, Q31 - sts[0]->hFdCngDec->bandNoiseShape_exp, FFTLEN2); + fixedToFloat_arrL(&DFT_fx[0][0], &DFT[0][0], q_dft, sizeof(DFT) / sizeof(DFT[0][0])); + } +#endif /* decoding */ IF( EQ_16( hCPE->nchan_out, 1 ) ) @@ -1013,7 +1070,6 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); } } @@ -1029,7 +1085,6 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); } @@ -1091,7 +1146,6 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } @@ -1116,7 +1170,6 @@ ivas_error ivas_cpe_dec_fx( { hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) @@ -1163,7 +1216,7 @@ ivas_error ivas_cpe_dec_fx( * IC-BWE: output LB and HB mix in ACELP mode *----------------------------------------------------------------*/ - stereo_icBWE_decproc_fx(hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame); + stereo_icBWE_decproc_fx(hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame, q_output); smooth_dft2td_transition_fx( hCPE, output, output_frame ); @@ -1667,6 +1720,8 @@ void destroy_cpe_dec( hCPE->input_mem_LB_fx[n] = NULL; free( hCPE->input_mem_fx[n] ); hCPE->input_mem_fx[n] = NULL; + free(hCPE->output_mem_fx[n]); + hCPE->output_mem_fx[n] = NULL; #endif IF( hCPE->prev_synth_chs[n] != NULL ) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 1f3a3a0e033e9b3f13a5c5d3a01f5dce5df505b8..093493a9b8c654eb75404e5f3043e5e99bdc3021 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -3381,6 +3381,109 @@ void ivas_dirac_dec_set_md_map_fx( return; } #endif +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_dirac_dec_render_fx() + * + * DirAC decoding renderer process + *------------------------------------------------------------------------*/ + +void ivas_dirac_dec_render( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const Word16 nchan_transport, /* i : number of transport channels */ + 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 */ +) +{ + 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]; + float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; // VE2SB: TBV + + 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]; + + 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 ); + } + slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // cL + move16(); + + /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */ + slots_to_render = s_min( sub( hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); + + *nSamplesRendered = i_mult( slots_to_render, slot_size ); + move16(); + + first_sf = hSpatParamRendCom->subframes_rendered; + move16(); + last_sf = first_sf; + move16(); + + WHILE( GT_16( slots_to_render, 0 ) ) + { + slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); + last_sf++; + } + + FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + { + ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL ); + + n_samples_sf = i_mult( hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slot_size ); + + FOR( ch = 0; ch < nchan_intern; ch++ ) + { + output_f_local[ch] += n_samples_sf; + output_f_local_fx[ch] += n_samples_sf; + } + + /* update combined orientation access index */ + ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); + } + + FOR( ch = 0; ch < nchan_intern; ch++ ) + { + 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 ); + } + } + + IF( EQ_16( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->num_slots ) ) + { + IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) ) + { + temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); + } + ELSE + { + temp = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ); + hSpatParamRendCom->dirac_read_idx = sub( temp, i_mult( idiv1616( temp, hSpatParamRendCom->dirac_md_buffer_length ), hSpatParamRendCom->dirac_md_buffer_length ) ); + } + } + + *nSamplesAvailableNext = i_mult(sub(hSpatParamRendCom->num_slots, hSpatParamRendCom->slots_rendered), slot_size); + move16(); + + return; +} +#else /*------------------------------------------------------------------------- * ivas_dirac_dec_render() * @@ -3461,7 +3564,7 @@ void ivas_dirac_dec_render( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_render_sf() @@ -3479,12 +3582,6 @@ void ivas_dirac_dec_render_sf( int16_t i, ch, idx_in, idx_lfe; DIRAC_DEC_HANDLE hDirAC; DIRAC_REND_HANDLE hDirACRend; - float dirEne; - float surCohEner; - float surCohRatio[CLDFB_NO_CHANNELS_MAX]; -#ifdef IVAS_FLOAT_FIXED - set_zero( surCohRatio, CLDFB_NO_CHANNELS_MAX ); -#endif int16_t subframe_idx; int16_t slot_idx, index_slot; int16_t hodirac_flag; @@ -3496,8 +3593,6 @@ void ivas_dirac_dec_render_sf( float Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; - float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; int16_t index, num_freq_bands; /* local copies of azi, ele, diffuseness */ @@ -3507,17 +3602,33 @@ void ivas_dirac_dec_render_sf( #ifdef IVAS_FLOAT_FIXED Word32 diffuseness_vector_fx[CLDFB_NO_CHANNELS_MAX]; Word32 *p_Rmat_fx; - /////////////////////////////////// to be removed //////////////////////////////////////////////// - if ( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) - { - p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; - floatToFixed_arrL( &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0], p_Rmat_fx, Q29, 9 ); - } - else - { - p_Rmat_fx = 0; - } - ///////////////////////////////////////////////////////////////////////////////////////////////////////// + Word32 *reference_power_fx, *reference_power_smooth_fx, *onset_filter_fx, *onset_filter_subframe_fx; + Word32 dirEne_fx; + Word32 surCohEner_fx; + Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 surCohRatio_q_fx = 0, temp_q = 0; + Word16 diffuse_power_factor_q = 0, direct_power_factor_q = 0; + Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word16 cldfb_buf_q; + Word32 pppQMfFrame_ts_re_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 pppQMfFrame_ts_im_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + Word32 Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; + set_zero_fx(surCohRatio_fx, CLDFB_NO_CHANNELS_MAX); + Word16 q_cldfb;; + Word16 Q_cldfb_scale; + Word32 proto_frame_f_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX]; + Word32 proto_direct_buffer_f_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX]; + Word32 proto_power_smooth_fx[2 * CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS]; + Word32 reference_power_fix[5 * CLDFB_NO_CHANNELS_MAX]; + Word32 onset_filter_subframe_fix[2 * MAX_OUTPUT_CHANNELS]; + Word32 proto_diffuse_buffer_f_fx[2 * MAX_OUTPUT_CHANNELS * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX]; + set_zero_fx( &proto_frame_f_fx[0], 2 * MAX_OUTPUT_CHANNELS * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &proto_direct_buffer_f_fx[0], 2 * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS ); + set_zero_fx( &proto_power_smooth_fx[0], 2 * CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS ); + set_zero_fx( &reference_power_fix[0], 5 * CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( &proto_diffuse_buffer_f_fx[0], 2 * CLDFB_SLOTS_PER_SUBFRAME * CLDFB_NO_CHANNELS_MAX * MAX_OUTPUT_CHANNELS ); #endif DIRAC_DEC_STACK_MEM DirAC_mem; @@ -3539,7 +3650,577 @@ void ivas_dirac_dec_render_sf( reference_power_smooth = ( DirAC_mem.reference_power == NULL ) ? NULL : DirAC_mem.reference_power + hSpatParamRendCom->num_freq_bands; onset_filter = DirAC_mem.onset_filter; onset_filter_subframe = ( DirAC_mem.onset_filter == NULL ) ? NULL : DirAC_mem.onset_filter + hSpatParamRendCom->num_freq_bands; +#ifdef IVAS_FLOAT_FIXED + reference_power_fx = DirAC_mem.reference_power_fx; + reference_power_smooth_fx = ( DirAC_mem.reference_power_fx == NULL ) ? NULL : DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; + onset_filter_fx = DirAC_mem.onset_filter_fx; + onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + + //////////////////////////////////////////////////////////////////////////// to be removed /////////////////////////////////////////////////////////////////// + reference_power_smooth_fx = &reference_power_fix[hSpatParamRendCom->num_freq_bands]; + onset_filter_subframe_fx = &onset_filter_subframe_fix[hSpatParamRendCom->num_freq_bands]; + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( diffuseness_vector, hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]], Q30, hSpatParamRendCom->num_freq_bands ); + md_idx = hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->subframes_rendered]; + } + ELSE + { + set_zero( diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + md_idx = hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->slots_rendered]; + } + + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + set_zero( reference_power_smooth, hSpatParamRendCom->num_freq_bands ); + } + ELSE + { + set_zero( onset_filter_subframe, hSpatParamRendCom->num_freq_bands ); + } + + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) + { + p_Rmat = &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; + p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; + floatToFixed_arrL32( &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0], p_Rmat_fx, Q29, 9 ); + } + ELSE + { + p_Rmat = 0; + p_Rmat_fx = 0; + } + IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) + { + IF( EQ_16( hSpatParamRendCom->numParametricDirections, 2 ) ) + { + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, Q15, hDirACRend->num_outputs_dir ); + floatToFixed_arrL32( hSpatParamRendCom->energy_ratio1[md_idx], hSpatParamRendCom->energy_ratio1_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( hSpatParamRendCom->energy_ratio2[md_idx], hSpatParamRendCom->energy_ratio2_fx[md_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + } + + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) + { + floatToFixed_arrL32( &st_ivas->hCombinedOrientationData->Rmat[st_ivas->hCombinedOrientationData->subframe_idx][0][0], &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0], Q29, 9 ); + } + + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[hSpatParamRendCom->subframes_rendered]; slot_idx++ ) + { + IF( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + floatToFixed_arrL32( pppQMfFrame_ts_re[ch][slot_idx], pppQMfFrame_ts_re_fx[ch][slot_idx], Q6, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( pppQMfFrame_ts_im[ch][slot_idx], pppQMfFrame_ts_im_fx[ch][slot_idx], Q6, hSpatParamRendCom->num_freq_bands ); + } + } + ELSE + { + Word32 offset = i_mult( hSpatParamRendCom->num_freq_bands, add( hSpatParamRendCom->slots_rendered, slot_idx ) ); + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + floatToFixed_arrL32( &st_ivas->hTcBuffer->tc[hDirACRend->sba_map_tc[ch]][offset], &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset], Q11, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( st_ivas->cldfbAnaDec[ch]->cldfb_state, st_ivas->cldfbAnaDec[ch]->cldfb_state_fx, Q11, ( st_ivas->cldfbAnaDec[ch]->p_filter_length - st_ivas->cldfbAnaDec[ch]->no_channels ) ); + } + } + } + + IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + { + floatToFixed_arrL32( st_ivas->hTcBuffer->tc[1], st_ivas->hTcBuffer->tc_fx[1], Q11, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL32( st_ivas->cldfbAnaDec[1]->cldfb_state, st_ivas->cldfbAnaDec[1]->cldfb_state_fx, Q11, ( st_ivas->cldfbAnaDec[1]->p_filter_length - st_ivas->cldfbAnaDec[1]->no_channels ) ); + } + + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) ) + { + st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth, st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth, st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth, st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_fx = floatToFixed_32( st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth, st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_q ); + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); + + IF( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) + { + coherence_flag = st_ivas->hQMetaData->coherence_flag; + move16(); + } + ELSE + { + coherence_flag = 0; + move16(); + } + /* Subframe loop */ + slot_idx_start = hSpatParamRendCom->slots_rendered; + move16(); + slot_idx_start_cldfb_synth = 0; + move16(); + subframe_idx = hSpatParamRendCom->subframes_rendered; + move16(); + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + move16(); + } + ELSE + { + md_idx = hSpatParamRendCom->render_to_md_map[slot_idx_start]; + move16(); + } + + /* copy parameters into local buffers*/ + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); + Copy( hSpatParamRendCom->azimuth[hSpatParamRendCom->render_to_md_map[subframe_idx]], azimuth, hSpatParamRendCom->num_freq_bands ); + Copy( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); + } + ELSE + { + set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands ); + } + + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + set_zero_fx( reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands ); + } + ELSE + { + set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); + } + + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) + { + p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; + + IF( EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + { + num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; + move16(); + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + rotateAziEle_DirAC_fx( azimuth, elevation, num_freq_bands, hSpatParamRendCom->num_freq_bands, p_Rmat_fx ); + } + } + } + ELSE + { + p_Rmat_fx = 0; + } + + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) + { + /* compute response */ + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands, + diffuseness_vector_fx, + hDirACRend->h_output_synthesis_psd_params.max_band_decorr, + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx ); + + direct_power_factor_q = Q29; + move16(); + diffuse_power_factor_q = Q29; + move16(); + + IF( coherence_flag ) + { + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; // Q29 + move32(); + surCohEner_fx = Mpy_32_16_1( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); // Q29 + Q15 - Q15 = Q29 + + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i] = L_sub( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], surCohEner_fx ); // Q29 + move32(); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i] = L_add( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], surCohEner_fx ); // Q29 + move32(); + + surCohRatio_fx[i] = BASOP_Util_Divide3232_Scale( surCohEner_fx, ( L_add( EPSILLON_FX, L_add( dirEne_fx, surCohEner_fx ) ) ), &temp_q ); + move32(); + surCohRatio_fx[i] = L_shl( surCohRatio_fx[i], temp_q ); + move32(); + } + } + ELSE + { + set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands ); + } + surCohRatio_q_fx = Q15; + move16(); + } + ELSE + { + Word16 max_exp_direct = 0, max_exp_diffusion = 0; + ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands, + hSpatParamRendCom->diffuseness_vector_fx[md_idx], + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, + &max_exp_direct, &max_exp_diffusion ); + + direct_power_factor_q = sub( Q31, max_exp_direct ); + diffuse_power_factor_q = sub( Q31, max_exp_diffusion ); + + IF( coherence_flag ) + { + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + surCohRatio_fx[i] = (Word32) hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]; + move32(); + } + } + ELSE + { + set_zero_fx( surCohRatio_fx, hSpatParamRendCom->num_freq_bands ); + } + surCohRatio_q_fx = Q15; + move16(); + } + + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 1 ) ) + { + ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, + hDirACRend, + st_ivas->hVBAPdata, + st_ivas->hMasa == NULL ? NULL : st_ivas->hMasa->data.band_mapping, + st_ivas->hMasaIsmData, + azimuth, + elevation, + md_idx, + surCohRatio_fx, + surCohRatio_q_fx, + st_ivas->hCombinedOrientationData->shd_rot_max_order, + p_Rmat_fx, + hodirac_flag ); + } + ELSE + { + ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, + hDirACRend, + st_ivas->hVBAPdata, + st_ivas->hMasa == NULL ? NULL : st_ivas->hMasa->data.band_mapping, + st_ivas->hMasaIsmData, + azimuth, + elevation, + md_idx, + surCohRatio_fx, + surCohRatio_q_fx, + 0, + NULL, + hodirac_flag ); + } + } + + IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + index_slot = add( slot_idx_start, slot_idx ); + Word32 offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot ); + /* CLDFB Analysis*/ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Q_cldfb_scale = Q11; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset], + Cldfb_RealBuffer_Temp_fx[ch][slot_idx], + Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch], &Q_cldfb_scale ); + } + } + + IF( L_and( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ), NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) + { + ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); + } + } + + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + index_slot = add( slot_idx_start, slot_idx ); + IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) ) + { + md_idx = hSpatParamRendCom->render_to_md_map[index_slot]; + move16(); + } + ELSE + { + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + move16(); + } + IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Copy32( pppQMfFrame_ts_re_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); + Copy32( pppQMfFrame_ts_im_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); + } + } + ELSE IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Copy32( Cldfb_RealBuffer_Temp_fx[ch][slot_idx], Cldfb_RealBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); + Copy32( Cldfb_ImagBuffer_Temp_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][0], hSpatParamRendCom->num_freq_bands ); + } + } + ELSE + { + /* CLDFB Analysis*/ + Word32 offset = i_mult( hSpatParamRendCom->num_freq_bands, index_slot ); + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + Q_cldfb_scale = Q11; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &st_ivas->hTcBuffer->tc_fx[hDirACRend->sba_map_tc[ch]][offset], + Cldfb_RealBuffer_fx[ch][0], + Cldfb_ImagBuffer_fx[ch][0], + hSpatParamRendCom->num_freq_bands, + st_ivas->cldfbAnaDec[ch], &Q_cldfb_scale ); + } + } + + /* CNG in DirAC, extra CLDFB ana for CNA*/ + IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + { + Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; + Q_cldfb_scale = Q11; + move16(); + Word16 Q_input = Q11; + move16(); + generate_masking_noise_dirac_fx( st->hFdCngDec->hFdCngCom, + st_ivas->cldfbAnaDec[1], + st_ivas->hTcBuffer->tc_fx[1], + Cldfb_RealBuffer_fx[1][0], + Cldfb_ImagBuffer_fx[1][0], + index_slot, + st->cna_dirac_flag && st->flag_cna, + ( L_or( EQ_32( st->core_brate, FRAME_NO_DATA ), EQ_32( st->core_brate, SID_2k40 ) ) ) && EQ_16( st->cng_type, FD_CNG ) && st->cng_sba_flag, Q_input, &Q_cldfb_scale ); + Scale_sig32( Cldfb_RealBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_cldfb_scale ) ); + Scale_sig32( Cldfb_ImagBuffer_fx[1][0], CLDFB_NO_CHANNELS_MAX, sub( Q6, Q_cldfb_scale ) ); + } + + /* LFE synthesis */ + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) ) + { + Word16 cldfb_q = Q6; + move16(); + ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth, + Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1], Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1], + slot_idx, + md_idx, + nchan_transport, cldfb_q ); + } + + + /////////////////////////////////////////////////////// to be removed ///////////////////////////////////////////////////////////////////////// + IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) && EQ_16( slot_idx, 0 ) ) + { + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, diffuse_power_factor_q, hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, direct_power_factor_q, hSpatParamRendCom->num_freq_bands ); + } + ELSE + { + me2f_buf( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, 31 - diffuse_power_factor_q, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor, hSpatParamRendCom->num_freq_bands ); + me2f_buf( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, 31 - direct_power_factor_q, hDirACRend->h_output_synthesis_psd_state.direct_power_factor, hSpatParamRendCom->num_freq_bands ); + } + } + + IF( st_ivas->hMasa == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + + IF( hodirac_flag ) + { + fixedToFloat_arrL32( &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], &hDirACRend->h_output_synthesis_psd_state.direct_responses[i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir )], hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + ELSE + { + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + { + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_square, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + } + + IF( !( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) ) + { + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + fixedToFloat_arrL32( st_ivas->cldfbAnaDec[ch]->cldfb_state_fx, st_ivas->cldfbAnaDec[ch]->cldfb_state, Q11, ( st_ivas->cldfbAnaDec[ch]->p_filter_length - st_ivas->cldfbAnaDec[ch]->no_channels ) ); + } + } + + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + fixedToFloat_arrL32( Cldfb_RealBuffer_fx[ch][0], Cldfb_RealBuffer[ch][0], Q6, hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL32( Cldfb_ImagBuffer_fx[ch][0], Cldfb_ImagBuffer[ch][0], Q6, hSpatParamRendCom->num_freq_bands ); + } + + IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) + { + fixedToFloat_arrL32( st_ivas->cldfbAnaDec[1]->cldfb_state_fx, st_ivas->cldfbAnaDec[1]->cldfb_state, Q11, ( st_ivas->cldfbAnaDec[1]->p_filter_length - st_ivas->cldfbAnaDec[1]->no_channels ) ); + fixedToFloat_arrL32( Cldfb_RealBuffer_fx[1][0], Cldfb_RealBuffer[1][0], Q6, CLDFB_NO_CHANNELS_MAX ); + fixedToFloat_arrL32( Cldfb_ImagBuffer_fx[1][0], Cldfb_ImagBuffer[1][0], Q6, CLDFB_NO_CHANNELS_MAX ); + } + + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) ) + { + FOR( i = 0; i < nchan_transport; i++ ) + { + Cldfb_RealBuffer[i][0][0] = fixedToFloat_32( Cldfb_RealBuffer_fx[i][0][0], Q6 ); + Cldfb_ImagBuffer[i][0][0] = fixedToFloat_32( Cldfb_ImagBuffer_fx[i][0][0], Q6 ); + } + fixedToFloat_arrL32( Cldfb_RealBuffer_fx[MAX_OUTPUT_CHANNELS - 1][slot_idx], Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS - 1][slot_idx], Q6, CLDFB_NO_CHANNELS_MAX ); + fixedToFloat_arrL32( Cldfb_ImagBuffer_fx[MAX_OUTPUT_CHANNELS - 1][slot_idx], Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS - 1][slot_idx], Q6, CLDFB_NO_CHANNELS_MAX ); + st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->transportEneSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->protoLfeEneSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->targetEneLfeSmooth_q ); + st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth = fixedToFloat_32( st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_fx, st_ivas->hMasa->hMasaLfeSynth->targetEneTransSmooth_q ); + } + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + /*-----------------------------------------------------------------* + * protoype signal computation + *-----------------------------------------------------------------*/ + q_cldfb = Q6; + move16(); + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + { + protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + proto_diffuse_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, + slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + p_Rmat_fx, q_cldfb ); + } + ELSE + { + protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + proto_diffuse_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, + slot_idx, nchan_transport, + hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + 0, q_cldfb ); + } + /////////////////////////////////////////// to be removed /////////////////////////////////////////////// + fixedToFloat_arrL32( &proto_direct_buffer_f_fx[i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) )], hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f + i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, nchan_transport ) ), hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, 2 * nchan_transport * hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL32( &proto_diffuse_buffer_f_fx[i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) )], hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f + i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ), hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, 2 * s_min( nchan_transport, hDirACRend->num_outputs_diff ) * hSpatParamRendCom->num_freq_bands ); + IF( nchan_transport >= 4 ) + { + fixedToFloat_arrL32( reference_power_fix, reference_power, DirAC_mem.reference_power_q, 5 * hSpatParamRendCom->num_freq_bands ); + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + } + else if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) + { + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect ); + } + else + { + switch ( nchan_transport ) + { + case 11: + case 8: + case 6: + case 4: + ///////////////////////////////////////// to be removed ///////////////////////////////////////// + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff ); + /////////////////////////////////////////////////////////////////////////////////////////////// + protoSignalComputation4_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + proto_frame_f_fx, + &hDirACRend->proto_frame_f_q, + proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, + &DirAC_mem.reference_power_q, + proto_power_smooth_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + slot_idx, hDirACRend->num_outputs_diff, + hSpatParamRendCom->num_freq_bands, + hDirACRend->hoa_decoder, + nchan_transport, + hDirACRend->sba_map_tc, q_cldfb ); + //////////////////////////////////////////////// to be removed ///////////////////////////////////////////////////////// + Word16 offset = i_mult( i_mult( slot_idx, 2 ), i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); + fixedToFloat_arrL32( proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ); + fixedToFloat_arrL32( &proto_direct_buffer_f_fx[offset], &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f[offset], hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ) ); + fixedToFloat_arrL32( proto_frame_f_fx, hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_q, i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff ) ) ); + fixedToFloat_arrL32( reference_power_fix, reference_power, DirAC_mem.reference_power_q, hSpatParamRendCom->num_freq_bands ); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + break; + case 2: + protoSignalComputation2( Cldfb_RealBuffer, Cldfb_ImagBuffer, + hDirACRend->proto_frame_f, + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, + reference_power, + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, + hDirACRend->hOutSetup.is_loudspeaker_setup, + slot_idx, + hSpatParamRendCom->num_freq_bands, + hDirACRend->masa_stereo_type_detect ); + break; + case 1: + ////////////////////////////////// to be removed ///////////////////////////////////////////////////////// + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hSpatParamRendCom->num_freq_bands ); + ///////////////////////////////////////////////////////////////////////////////////////////////////////// + protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, + proto_frame_f_fx, + &hDirACRend->proto_frame_f_q, + proto_direct_buffer_f_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, + &DirAC_mem.reference_power_q, + proto_power_smooth_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + slot_idx, + hDirACRend->num_protos_diff, + hSpatParamRendCom->num_freq_bands, q_cldfb ); + ////////////////////////////// to be removed /////////////////////////////////////////////////////////////////////////////////////// + fixedToFloat_arrL32( proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hSpatParamRendCom->num_freq_bands ); + fixedToFloat_arrL32( &proto_direct_buffer_f_fx[i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) )], hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f + i_mult( slot_idx, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ), hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, i_mult( 2, hSpatParamRendCom->num_freq_bands ) ); + fixedToFloat_arrL32( proto_frame_f_fx, hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_q, i_mult( 2, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_protos_diff ) ) ); + fixedToFloat_arrL32( reference_power_fix, reference_power, DirAC_mem.reference_power_q, hSpatParamRendCom->num_freq_bands ); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + break; + default: + return; + } + } +#else + float dirEne; + float surCohEner; + float surCohRatio[CLDFB_NO_CHANNELS_MAX]; + float Cldfb_RealBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + float Cldfb_ImagBuffer_Temp[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; +#ifdef IVAS_FLOAT_FIXED + set_zero( surCohRatio, CLDFB_NO_CHANNELS_MAX ); +#endif hodirac_flag = ivas_get_hodirac_flag( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); if ( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) { @@ -3572,14 +4253,14 @@ void ivas_dirac_dec_render_sf( mvs2s( hSpatParamRendCom->elevation[hSpatParamRendCom->render_to_md_map[subframe_idx]], elevation, hSpatParamRendCom->num_freq_bands ); mvr2r( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); #ifdef IVAS_FLOAT_FIXED - Copy32(hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands); + Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); #endif } else { set_zero( diffuseness_vector, hSpatParamRendCom->num_freq_bands ); #ifdef IVAS_FLOAT_FIXED - set32_fx(diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands); + set32_fx( diffuseness_vector_fx, 0, hSpatParamRendCom->num_freq_bands ); #endif } @@ -4022,7 +4703,7 @@ void ivas_dirac_dec_render_sf( return; } } - +#endif /*-----------------------------------------------------------------* * Compute DirAC parameters at decoder side diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 433a971923d995d57850a8e61246081bf7be6858..fdb08288dd2e17f761a688c6699eb54bcc44643e 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -283,8 +283,8 @@ static ivas_error ivas_ism_bitrate_switching_dec( return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index eb93e7a7f1717c9a80dba2711f7a2c043c12edff..a8ea0e9b5f61cda6356c997fa1b086109676d594 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -1113,11 +1113,6 @@ ivas_error ivas_jbm_dec_tc( ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fix, output_frame, st_ivas->ivas_format == MC_FORMAT ); - IF (hSCE != NULL) - { - hSCE->hCoreCoder[0]->log_energy_diff_lt = fixedToFloat(hSCE->hCoreCoder[0]->log_energy_diff_lt_fx, Q15); - hSCE->hCoreCoder[0]->stab_fac_smooth_lt = fixedToFloat(hSCE->hCoreCoder[0]->stab_fac_smooth_lt_fx, Q15); - } fixedToFloat_arrL(&hCPE->prev_synth_fx[0][0], &hCPE->prev_synth[0][0], hCPE->q_prev_synth_fx, sizeof(hCPE->prev_synth) / sizeof(hCPE->prev_synth[0][0])); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx, 15 ); @@ -2101,11 +2096,6 @@ ivas_error ivas_jbm_dec_tc( ivas_sba_dirac_stereo_dec_fx( st_ivas, &p_output_fix[sba_ch_idx], output_frame, 0 ); - IF (hSCE != NULL) - { - hSCE->hCoreCoder[0]->log_energy_diff_lt = fixedToFloat(hSCE->hCoreCoder[0]->log_energy_diff_lt_fx, Q15); - hSCE->hCoreCoder[0]->stab_fac_smooth_lt = fixedToFloat(hSCE->hCoreCoder[0]->stab_fac_smooth_lt_fx, Q15); - } fixedToFloat_arrL(&hCPE->prev_synth_fx[0][0], &hCPE->prev_synth[0][0], hCPE->q_prev_synth_fx, sizeof(hCPE->prev_synth) / sizeof(hCPE->prev_synth[0][0])); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx, 15 ); @@ -3185,11 +3175,6 @@ ivas_error ivas_jbm_dec_tc( ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fix, output_frame, 1 ); - IF (hSCE != NULL) - { - hSCE->hCoreCoder[0]->log_energy_diff_lt = fixedToFloat(hSCE->hCoreCoder[0]->log_energy_diff_lt_fx, Q15); - hSCE->hCoreCoder[0]->stab_fac_smooth_lt = fixedToFloat(hSCE->hCoreCoder[0]->stab_fac_smooth_lt_fx, Q15); - } fixedToFloat_arrL(&hCPE->prev_synth_fx[0][0], &hCPE->prev_synth[0][0], hCPE->q_prev_synth_fx, sizeof(hCPE->prev_synth) / sizeof(hCPE->prev_synth[0][0])); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_rescale_fact_fx, 15 ); st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact = fixedToFloat( st_ivas->hCPE[0]->hCoreCoder[0]->hFdCngDec->cna_act_fact_fx, 15 ); @@ -7395,14 +7380,14 @@ Word16 ivas_jbm_dec_get_num_tc_channels_fx( { IF( st_ivas->hOutSetup.separateChannelEnabled ) { - num_tc = add( num_tc, st_ivas->nchan_ism ); + num_tc = add( num_tc, 1 ); } IF( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) ) ) { /* LFE is synthesized in TD with the TCs*/ - num_tc = add( num_tc, st_ivas->nchan_ism ); + num_tc = add( num_tc, 1 ); } } } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 77f838d9846780a10c2db9373fbfa0bb0ac60f5a..cb6157a0679603d3d0b930ba4ba2171fb438e5b7 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -2572,12 +2572,20 @@ static ivas_error init_lfe_synth_data_fx( #endif hMasa->hMasaLfeSynth->transportEneSmooth_fx = 0; + move32(); + hMasa->hMasaLfeSynth->transportEneSmooth_q = Q31; move16(); hMasa->hMasaLfeSynth->protoLfeEneSmooth_fx = 0; + move32(); + hMasa->hMasaLfeSynth->protoLfeEneSmooth_q = Q31; move16(); hMasa->hMasaLfeSynth->targetEneLfeSmooth_fx = 0; + move32(); + hMasa->hMasaLfeSynth->targetEneLfeSmooth_q = Q31; move16(); hMasa->hMasaLfeSynth->targetEneTransSmooth_fx = 0; + move32(); + hMasa->hMasaLfeSynth->targetEneTransSmooth_q = Q31; move16(); #if 1 /* TODO: remove float code. */ @@ -3364,8 +3372,8 @@ ivas_error ivas_masa_dec_reconfigure( return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) @@ -3899,8 +3907,8 @@ ivas_error ivas_masa_dec_reconfigure_fx( return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 9c519146cbeb8ff73a5ae6798b187485f429e337..a00b13ab88dd6aa77e12d8610add9afa33f4308a 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -892,7 +892,7 @@ ivas_error ivas_mct_dec( sts[ch]->hTcxLtpDec->tcxltp_gain = (Word16)floatToFixed( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); //sts[ch]->inv_gamma = (Word16)floatToFixed( 1 / sts[ch]->gamma_float, Q14 ); //sts[ch]->hTcxCfg->preemph_fac = (Word16)floatToFixed( sts[ch]->hTcxCfg->preemph_fac_flt, Q15 ); - f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); + //f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); f2me_16( sts[ch]->last_concealed_gain_syn_deemph_float, &sts[ch]->last_concealed_gain_syn_deemph, &sts[ch]->last_concealed_gain_syn_deemph_e ); f2me_16( sts[ch]->hTcxDec->old_gaintcx_bfi_float, &sts[ch]->hTcxDec->old_gaintcx_bfi, &sts[ch]->hTcxDec->old_gaintcx_bfi_e ); @@ -1150,7 +1150,7 @@ ivas_error ivas_mct_dec( sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); - sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); + //sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); //sts[ch]->stab_fac = fix16_to_float( sts[ch]->stab_fac_fx, Q15 ); // 16bit to u8bit @@ -1228,8 +1228,249 @@ ivas_error ivas_mct_dec( x[n][0] = output[n + cpe_id * CPE_CHANNELS]; x[n][1] = output[n + cpe_id * CPE_CHANNELS] + ( L_FRAME48k / 2 ); } +#ifdef IVAS_FLOAT_FIXED + // + + Word16 synth_fx16[2][1200]; + Word16 e_sig = 17; + + Word32 *x_fx_[2][2]; + Word16 q_x = Q11; + Word16 x_e_; + FOR(i = 0; i < 2; i++) { + FOR(j = 0; j < 2; j++) { + x_fx_[i][j] = malloc(960 * sizeof(Word32)); + } + } + x_e_ = 31 - q_x; + IF(synth[0]) floatToFixed_arr(synth[0], synth_fx16[0], 15-e_sig, 960); + IF(synth[1]) floatToFixed_arr(synth[1], synth_fx16[1], 15-e_sig, 960); + FOR( ch = 0; ch < 2; ch++) { + st = hCPE->hCoreCoder[ch]; - ivas_mdct_core_reconstruct( hCPE, x, synth, fUseTns[cpe_id], 1 ); + FOR( i = 0; i < 960; i++) { + x_fx_[ch][0][i] = (Word32)(x[ch][0][i] * (1 << q_x)); + } + FOR( i = 0; i < 480; i++) { + x_fx_[ch][1][i] = (Word32)(x[ch][1][i] * (1 << q_x)); + } + st->hIGFDec->virtualSpec_e = x_e_; + IF ( NE_16(st->igf, 0) && st->hIGFDec && st->hIGFDec->virtualSpec_fx ) + FOR( i = 0; i < s_min(st->hIGFDec->infoIGFStopLine - st->hIGFDec->infoIGFStartLine, 856); i++) { + st->hIGFDec->virtualSpec_fx[st->hIGFDec->infoIGFStartLine - IGF_START_MN + i] = (Word32)(st->hIGFDec->virtualSpec_float[st->hIGFDec->infoIGFStartLine - IGF_START_MN + i] * (1 << (31 - st->hIGFDec->virtualSpec_e))); + } + IF(st->hTcxDec)st->hTcxDec->tcxltp_last_gain_unmodified = float_to_fix16( st->hTcxDec->tcxltp_last_gain_unmodified_float, Q15 ); + + IF(st->hTcxDec) st->hTcxDec->conceal_eof_gain = (Word16)(st->hTcxDec->conceal_eof_gain_float * 16384.f); + st->last_concealed_gain_syn_deemph = (Word16)(st->last_concealed_gain_syn_deemph_float * 32767.f); + + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_float, st->hTcxDec->syn_Overl, st->Q_syn, L_FRAME32k / 2); + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_OverlFB_float, st->hTcxDec->syn_OverlFB, st->Q_syn, L_FRAME_MAX / 2); + IF(st->hTcxDec) st->hTcxDec->gainHelper = float_to_fix16( st->hTcxDec->gainHelper_float, Q14 ); + IF(st->hTcxDec) st->hTcxDec->gainHelper_e = 1; + IF(st->hTcxDec) st->hTcxDec->stepCompensate = float_to_fix16( st->hTcxDec->stepCompensate_float, Q14 ); + IF(st->hTcxDec) st->hTcxDec->stepCompensate_e = 1; + st->preemph_fac = float_to_fix16( st->preemph_fac_float, Q15 ); + IF(st->hTcxDec) st->hTcxDec->damping = float_to_fix16( st->hTcxDec->damping_float, Q14 ); + st->old_fpitch = float_to_fix( st->old_fpitch_float, Q16 ); + + st->prev_Q_syn = st->Q_syn; + st->old_fpitchFB = (Word32) ( st->old_fpitchFB_float * ONE_IN_Q16 ); + IF(hCPE->hStereoMdct) hCPE->hStereoMdct->lastCoh_fx = (Word16)(hCPE->hStereoMdct->lastCoh * (1<<14)); + st->lp_gainp_fx = (Word16)floatToFixed(st->lp_gainp, 14); + IF(st->hTonalMDCTConc) st->hTonalMDCTConc->lastPitchLag = float_to_fix(st->hTonalMDCTConc->lastPitchLag_float, Q16); + + st->enr_old_fx = (Word32)st->enr_old; + + IF(st->hHQ_core) floatToFixed_arr(st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->Q_syn, L_FRAME32k); + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, -1 - st->Q_syn, L_FRAME_MAX / 2); + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_TDAC_float, st->hTcxDec->syn_Overl_TDAC, -1 - st->Q_syn, L_FRAME32k / 2); + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1 - st->Q_syn, L_FRAME32k / 2); + //floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M ); + //floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM ); + floatToFixed_arr( st->syn_float, st->syn, st->Q_syn, M + 1 ); + //floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); + + IF(st->hTcxDec) st->hTcxDec->tcxltp_third_last_pitch = float_to_fix(st->hTcxDec->tcxltp_third_last_pitch_float, 16); + IF(st->hTcxDec) st->hTcxDec->tcxltp_second_last_pitch = float_to_fix(st->hTcxDec->tcxltp_second_last_pitch_float, 16); + IF(st->hTcxDec) st->hTcxLtpDec->tcxltp_gain = (Word16)floatToFixed(st->hTcxLtpDec->tcxltp_gain_float, Q15); + + IF(st->hBPF) st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_excFB, st->hTcxDec->old_excFB_fx, st->Q_exc, st->L_frame); + + st->Mode2_lp_gainc = (Word32) (st->lp_gainc * ONE_IN_Q16); + st->Mode2_lp_gainp= (Word32) (st->lp_gainp * ONE_IN_Q29); + st->cummulative_damping = (Word16) (st->cummulative_damping_float * MAX_16); + st->old_enr_LP = (Word16) (st->old_enr_LP_float * ONE_IN_Q3); + + if ( !st->tcxonly ) + { + floatToFixed_arr( st->p_bpf_noise_buf_float, st->p_bpf_noise_buf, 0, L_FRAME_16k ); + } + IF(st->hBPF) floatToFixed_arr( st->hBPF->pst_old_syn, st->hBPF->pst_old_syn_fx, 0, NBPSF_PIT_MAX ); + + floatToFixed_arr( st->lsp_old, st->lsp_old_fx, Q15, M ); + + IF(st->hBPF) st->mem_error = floatToFixed( st->hBPF->pst_mem_deemp_err, Q16 ); + + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_synth_float, st->hTcxDec->old_synth, st->Q_syn, 1280); + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_synthFB, st->hTcxDec->old_synthFB_fx, st->Q_syn, s_max(st->hTcxDec->L_frameTCX, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ))); + IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->synth_history, st->hTcxDec->synth_history_fx, st->Q_syn, NS2SA( st->output_Fs, PH_ECU_MEM_NS )); + + float maxim = 0; + IF(st->hFdCngDec && st->hFdCngDec->hFdCngCom) { + FOR(Word16 ind = 0; ind < 340; ind++) + { + maxim = fmaxf(maxim, fabsf(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind])); + } + st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 0; + IF(L_abs((Word32)maxim)!=0) st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - norm_l((Word32)maxim); + FOR(Word16 ind = 0; ind < 340; ind++) + { + st->hFdCngDec->hFdCngCom->cngNoiseLevel[ind] = (Word32)(st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[ind] * (1LL<<(31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); + } + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); + } + IF(st->hHQ_core) floatToFixed_arr(st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->Q_syn, 960); + IF(st->hTonalMDCTConc) floatToFixed_arr(st->hTonalMDCTConc->lastPcmOut_float, st->hTonalMDCTConc->lastPcmOut, 0, st->hTonalMDCTConc->nSamples); + IF(st->hTonalMDCTConc) floatToFixed_arr(st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, 0, st->hTonalMDCTConc->nSamples / 2); + if ( st->hPlcInfo ) + { + st->hPlcInfo->step_concealgain_fx = float_to_fix16( st->hPlcInfo->step_concealgain, Q15 ); + st->hPlcInfo->recovery_gain_float = float_to_fix16( st->hPlcInfo->recovery_gain, Q14 ); + } + IF(st->hTcxDec) + st->hTcxDec->conceal_eof_gain = float_to_fix16( st->hTcxDec->conceal_eof_gain_float, Q14 ); + if ( st->hTcxDec && st->hTcxDec->conCngLevelBackgroundTrace_e < 0 ) + { + st->hTcxDec->conCngLevelBackgroundTrace_e = 0; + } + /*IF(st->hTcxDec) st->hTcxDec->conCngLevelBackgroundTrace = (Word16)floatToFixed(st->hTcxDec->CngLevelBackgroundTrace_bfi, 15); + st->hTcxDec->conCngLevelBackgroundTrace_e = 0;*/ + IF(st->hTcxDec) f2me_16(st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e); + if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) + { + st->hTcxDec->conLastFrameLevel_e = 0; + } + IF(st->hTcxDec) st->hTcxDec->conLastFrameLevel = (Word16) floatToFixed( st->hTcxDec->LastFrameLevel_bfi, 15 - st->hTcxDec->conLastFrameLevel_e ); + if ( st->hTcxDec && st->hTcxDec->conNoiseLevelMemory_e[0] < 0 ) + { + set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); + } + //IF(st->hTcxDec) floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); + for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) + { + //st->hTcxDec->conNoiseLevelMemory_e[p] = 0; + //f2me_16(st->hTcxDec->NoiseLevelMemory_bfi[p], &st->hTcxDec->conNoiseLevelMemory[p], &st->hTcxDec->conNoiseLevelMemory_e[p]); + } + IF(st->hTcxDec) st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + IF(st->hTcxDec) st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); + IF(st->hTcxDec) for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB_fx[p] = (Word16) ( st->hTcxDec->old_excFB[p] * ( 1u << st->Q_exc ) ); + } + IF(st->hFdCngDec && st->hFdCngDec->hFdCngCom) floatToFixed_arr(st->hFdCngDec->hFdCngCom->A_cng_flt, st->hFdCngDec->hFdCngCom->A_cng, 15, 17); + st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); + } + FOR( Word16 ind = 0; ind < M + 1; ind++ ) + { + hCPE->hCoreCoder[0]->old_Aq_12_8_fx[ind] = (Word16) ( hCPE->hCoreCoder[0]->old_Aq_12_8[ind] * 4096.f ); + hCPE->hCoreCoder[1]->old_Aq_12_8_fx[ind] = (Word16) ( hCPE->hCoreCoder[1]->old_Aq_12_8[ind] * 4096.f ); + hCPE->hCoreCoder[0]->old_Aq_12_8_fx_32[ind] = (Word32)(hCPE->hCoreCoder[0]->old_Aq_12_8[ind] * (1<<28)); + hCPE->hCoreCoder[1]->old_Aq_12_8_fx_32[ind] = (Word32)(hCPE->hCoreCoder[1]->old_Aq_12_8[ind] * (1<<28)); + } + // + ivas_mdct_core_reconstruct_fx( hCPE, x_fx_, synth_fx16, fUseTns[cpe_id], 1, q_x, e_sig ); + // + IF(hCPE->hStereoMdct) hCPE->hStereoMdct->lastCoh = fix16_to_float(hCPE->hStereoMdct->lastCoh_fx, 14); + IF(synth[0]) fixedToFloat_arr(synth_fx16[0], synth[0], 15 - e_sig, 960); + IF(synth[1]) fixedToFloat_arr(synth_fx16[1], synth[1], 15 - e_sig, 960); + FOR( ch = 0; ch < 2; ch++) { + st = hCPE->hCoreCoder[ch]; + IF(st->igf) me2f_buf(x_fx_[ch][0], 31 - q_x, x[ch][0], 960 ); + IF(st->igf) me2f_buf(x_fx_[ch][1], 31 - q_x, x[ch][1], 480 ); + fixedToFloat_arr(st->hTcxDec->syn_OverlFB, st->hTcxDec->syn_OverlFB_float, st->Q_syn, L_FRAME_MAX / 2); + fixedToFloat_arr(st->hTcxDec->syn_Overl, st->hTcxDec->syn_Overl_float, st->Q_syn, L_FRAME32k / 2); + fixedToFloat_arr( st->syn, st->syn_float, st->Q_syn, M + 1 ); + st->hTonalMDCTConc->lastPitchLag_float = fix_to_float(st->hTonalMDCTConc->lastPitchLag, Q16); + st->hTcxDec->tcxltp_third_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_third_last_pitch, 16); + st->hTcxDec->tcxltp_second_last_pitch_float = fix_to_float(st->hTcxDec->tcxltp_second_last_pitch, 16); + st->old_fpitch_float = fix_to_float(st->old_fpitch, 16); + st->old_fpitchFB_float = fix_to_float(st->old_fpitchFB, 16); + st->hTcxDec->tcxltp_last_gain_unmodified_float = fix16_to_float( st->hTcxDec->tcxltp_last_gain_unmodified, Q15 ); + st->hTcxLtpDec->tcxltp_gain_float = fix16_to_float( st->hTcxLtpDec->tcxltp_gain, Q15 ); + st->hTcxDec->conceal_eof_gain_float = fix16_to_float( st->hTcxDec->conceal_eof_gain, Q14 ); + FOR(Word16 ind = 0; ind < 17; ind++) { + st->old_Aq_12_8[ind] = (float)(st->old_Aq_12_8_fx[ind]) / (float)(1<<12); + } + + IF(st->hBPF) st->hBPF->pst_mem_deemp_err = fixedToFloat( st->mem_error, Q16 ); + for ( int p = 0; p < st->L_frame; p++ ) + { + st->hTcxDec->old_excFB[p] = (float) ( st->hTcxDec->old_excFB_fx[p] ) / ( 1u << st->Q_exc ); + } + st->preemph_fac_float = (float) st->preemph_fac / MAX_16; + st->lp_gainc = (float) st->Mode2_lp_gainc / ONE_IN_Q16; + st->lp_gainp = (float) st->Mode2_lp_gainp / ONE_IN_Q29; + st->cummulative_damping_float = (float) st->cummulative_damping / MAX_16; + st->old_enr_LP_float = (float) st->old_enr_LP / ONE_IN_Q3; + for ( int p = 0; p < st->L_frame / 2; p++ ) + { + st->hTcxDec->old_syn_Overl_float[p] = (float) st->hTcxDec->old_syn_Overl[p] * 2 * ( 1u << st->Q_syn ); + st->hTcxDec->syn_Overl_TDACFB_float[p] = (float) st->hTcxDec->syn_Overl_TDACFB[p] * 2 * pow( 2, st->Q_syn ); + st->hTcxDec->syn_Overl_TDAC_float[p] = (float) st->hTcxDec->syn_Overl_TDAC[p] * 2 * pow( 2, st->Q_syn ); + } + for ( int p = 0; p < 640; p++ ) + { + st->hHQ_core->old_outLB[p] = (float) st->hHQ_core->old_out_LB_fx[p] / ( 1u << st->Q_syn ); + } + + if ( !st->tcxonly ) + { + fixedToFloat_arr( st->p_bpf_noise_buf, st->p_bpf_noise_buf_float, 0, L_FRAME_16k ); + } + IF(st->hBPF && st->hBPF->pst_old_syn) fixedToFloat_arr( st->hBPF->pst_old_syn_fx, st->hBPF->pst_old_syn, 0, NBPSF_PIT_MAX ); + st->enr_old = (float)st->enr_old_fx; + //me2f_buf_16(st->old_lsp_q_cng, e_lsp, st->old_lsp_q_cng_float, 16); + + fixedToFloat_arr(st->hTcxDec->old_synth, st->hTcxDec->old_synth_float, st->Q_syn, 1280); + fixedToFloat_arr(st->hTcxDec->synth_history_fx, st->hTcxDec->synth_history, st->Q_syn, NS2SA( st->output_Fs, PH_ECU_MEM_NS )); + fixedToFloat_arr(st->hTcxDec->old_synthFB_fx, st->hTcxDec->old_synthFB, st->Q_syn, st->hTcxDec->old_synth_lenFB + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS )); + + for ( int p = 0; p < 960; p++ ) + { + st->hHQ_core->old_out[p] = (float) st->hHQ_core->old_out_fx[p] / ( 1u << st->Q_syn ); + } + + if ( st->hPlcInfo ) + { + st->hPlcInfo->recovery_gain_float = fix16_to_float( st->hPlcInfo->recovery_gain, Q14 ); + st->hPlcInfo->step_concealgain = fix16_to_float( st->hPlcInfo->step_concealgain_fx, Q15 ); + } + fixedToFloat_arrL( st->old_pitch_buf_fx, st->old_pitch_buf, Q16, 2 * NB_SUBFR16k + 2 ); + IF(st->hTcxDec) st->hTcxDec->CngLevelBackgroundTrace_bfi = me2f_16(st->hTcxDec->conCngLevelBackgroundTrace, st->hTcxDec->conCngLevelBackgroundTrace_e); + //st->hTcxDec->CngLevelBackgroundTrace_bfi = fix16_to_float( st->hTcxDec->conCngLevelBackgroundTrace, 15 - st->hTcxDec->conCngLevelBackgroundTrace_e ); + st->hTcxDec->LastFrameLevel_bfi = me2f_16( st->hTcxDec->conLastFrameLevel, st->hTcxDec->conLastFrameLevel_e ); + for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) + { + //st->hTcxDec->NoiseLevelMemory_bfi[p] = me2f_16( st->hTcxDec->conNoiseLevelMemory[p], st->hTcxDec->conNoiseLevelMemory_e[p] ); + } + IF(st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float) fixedToFloat_arr(st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, st->hTonalMDCTConc->nSamples); + IF(sts[0]->bfi==0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) fixedToFloat_arr(st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, st->hTonalMDCTConc->nSamples / 2); + } + FOR( i = 0; i < 2; i++ ) + { + FOR( j = 0; j < 2; j++ ) + { + free(x_fx_[i][j]); + } + } + +#else + ivas_mdct_core_reconstruct( hCPE, x, signal_outFB_tmp, fUseTns[cpe_id], 1 ); +#endif + //ivas_mdct_core_reconstruct( hCPE, x, synth, fUseTns[cpe_id], 1 ); /*----------------------------------------------------------------* * CoreCoder Post-processing and updates @@ -1244,7 +1485,6 @@ ivas_error ivas_mct_dec( IF(hCPE->hCoreCoder[n]->hTcxLtpDec) { floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_out_32, q, L_FRAME48k); floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float, hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32, q, TCXLTP_MAX_DELAY); - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16)(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15); hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16)(hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15); floatToFixed_arrL(hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float, hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32, Q11, 111); } @@ -1286,14 +1526,16 @@ ivas_error ivas_mct_dec( delta = shr(Fs_kHz, 3); } +#if 0 if (sts[n]->hBWE_FD != NULL) { sts[n]->hBWE_FD->mem_deemph_old_syn_fx = (Word16)floatToFixed(sts[n]->hBWE_FD->mem_deemph_old_syn, 0); } +#endif IF(sts[n]->hHQ_core != NULL) { floatToFixed_arr(sts[n]->hHQ_core->old_out, sts[n]->hHQ_core->old_out_fx, 0, L_FRAME48k); - floatToFixed_arr(sts[n]->hHQ_core->fer_samples, sts[n]->hHQ_core->fer_samples_fx, 0, NS2SA(sts[n]->output_Fs, 3000000)); + //floatToFixed_arr(sts[n]->hHQ_core->fer_samples, sts[n]->hHQ_core->fer_samples_fx, 0, 960); //FOR(i = 0; i < SFM_N_WB; ++i) //{ // sts[n]->hHQ_core->prev_env_fx[i] = floatToFixed(sts[n]->hHQ_core->prev_env[i], sts[n]->hHQ_core->prev_env_Q[i]); @@ -1372,7 +1614,6 @@ ivas_error ivas_mct_dec( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << output_q ) ); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); } } @@ -1400,6 +1641,14 @@ ivas_error ivas_mct_dec( { hCPE->prev_synth_fx[n][k] = (Word32) ( hCPE->prev_synth[n][k] * ( 1 << output_q ) ); } + + floatToFixed_arr( sts[n]->tilt_code_dec, sts[n]->tilt_code_dec_fx, Q15, 5 ); + floatToFixed_arr( sts[n]->old_synth_sw, sts[n]->old_synth_sw_fx, -2, 429 ); + //sts[n]->prev_tilt_code_dec_fx = (Word16) floatToFixed( sts[n]->prev_tilt_code_dec, Q15 ); + FOR( Word16 ind = 0; ind < 16; ind++ ) + { + sts[n]->mem_AR_fx[ind] = (Word16) ( sts[n]->mem_AR[ind] * 2.56f ); + } } #endif FOR ( n = 0; n < CPE_CHANNELS; n++ ) @@ -1414,7 +1663,7 @@ ivas_error ivas_mct_dec( } /* Postprocessing for ACELP/MDCT core switching and synchronization */ - Word16 synth_fx16[L_FRAME48k]; + Word16 synth_fx_16[L_FRAME48k]; Word16 output_mem_fx[L_FRAME48k]; IF( hCPE->output_mem[1] != NULL ) { @@ -1425,14 +1674,14 @@ ivas_error ivas_mct_dec( set16_fx( output_mem_fx, 0, NS2SA( sts[n]->output_Fs, 3125000 ) ); } - Copy_Scale_sig_32_16(synth_fx[n], synth_fx16, L_FRAME48k, sub(Q_synth, Q11)); + Copy_Scale_sig_32_16(synth_fx[n], synth_fx_16, L_FRAME48k, sub(Q_synth, Q11)); - IF ( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx16, output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) + IF ( ( error = core_switching_post_dec_ivas_fx( sts[n], synth_fx_16, output_fx[cpe_id * CPE_CHANNELS + n], output_mem_fx, st_ivas->ivas_format, 0, output_frame, 0 /*core_switching_flag*/, ( st_ivas->ivas_format != SBA_ISM_FORMAT || cpe_id >= nCPE - 2 ) ? st_ivas->sba_dirac_stereo_flag : 0, -1, hCPE->last_element_mode, &Q_synth ) ) != IVAS_ERR_OK ) { return error; } - Copy_Scale_sig_16_32(synth_fx16, output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub(Q11, Q_synth)); + Copy_Scale_sig_16_32(synth_fx_16, output_fx[cpe_id * CPE_CHANNELS + n], output_frame, sub(Q11, Q_synth)); /* Save synthesis for HQ FEC */ Word32 output_fx_[L_FRAME48k]; @@ -1504,7 +1753,7 @@ ivas_error ivas_mct_dec( IF(sts[n]->hHQ_core != NULL) { fixedToFloat_arr(sts[n]->hHQ_core->old_out_fx, sts[n]->hHQ_core->old_out, 0, L_FRAME48k); - fixedToFloat_arr(sts[n]->hHQ_core->fer_samples_fx, sts[n]->hHQ_core->fer_samples, 0, NS2SA(sts[n]->output_Fs, 3000000)); + //fixedToFloat_arr(sts[n]->hHQ_core->fer_samples_fx, sts[n]->hHQ_core->fer_samples, 0, 960); //FOR(i = 0; i < SFM_N_WB; ++i) //{ // sts[n]->hHQ_core->prev_env[i] = fixedToFloat(sts[n]->hHQ_core->prev_env_fx[i], sts[n]->hHQ_core->prev_env_Q[i]); @@ -1522,23 +1771,25 @@ ivas_error ivas_mct_dec( Word8 reset_swb_tbe = 0; Word8 reset_swb_tbe_synth = 0; +#if 0 if (sts[n]->hBWE_FD != NULL) { sts[n]->hBWE_FD->mem_deemph_old_syn = fixedToFloat(sts[n]->hBWE_FD->mem_deemph_old_syn_fx, 0); } +#endif IF((NE_16(sts[n]->last_extl, SWB_BWE) && EQ_16(sts[n]->extl, SWB_BWE)) || (NE_16(sts[n]->last_extl, FB_BWE) && EQ_16(sts[n]->extl, FB_BWE)) || ((EQ_16(sts[n]->last_core, HQ_CORE) || EQ_16(sts[n]->last_extl, SWB_TBE)) && sts[n]->extl < 0 && NE_16(sts[n]->core, HQ_CORE)) || (EQ_16(sts[n]->last_core, ACELP_CORE) && EQ_16(sts[n]->core, ACELP_CORE) && ((NE_16(sts[n]->prev_coder_type, INACTIVE) && EQ_16(sts[n]->coder_type, INACTIVE)) || (NE_16(sts[n]->prev_coder_type, AUDIO) && EQ_16(sts[n]->coder_type, AUDIO))) && sts[n]->bws_cnt > 0)) { - fixedToFloat_arr(sts[n]->hBWE_FD->L_old_wtda_swb_fx, sts[n]->hBWE_FD->old_wtda_swb, 0, output_frame); + //fixedToFloat_arr(sts[n]->hBWE_FD->L_old_wtda_swb_fx, sts[n]->hBWE_FD->old_wtda_swb, 0, output_frame); - sts[n]->hBWE_FD->prev_Energy = fixedToFloat(sts[n]->hBWE_FD->prev_Energy_fx, 0); // setting to zero - sts[n]->hBWE_FD->prev_frica_flag = sts[n]->hBWE_FD->prev_frica_flag; // fixed - sts[n]->hBWE_FD->prev_td_energy = sts[n]->hBWE_FD->prev_td_energy_fx; // setting to zero - sts[n]->hBWE_FD->prev_weight = fixedToFloat(sts[n]->hBWE_FD->prev_weight_fx, 15); // 6554; /*0.2 in Q15*/ - sts[n]->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(sts[n]->prev_fb_ener_adjust_fx, 0); // setting to zero - fixedToFloat_arr(sts[n]->hBWE_FD->mem_imdct_fx, sts[n]->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero + //sts[n]->hBWE_FD->prev_Energy = fixedToFloat(sts[n]->hBWE_FD->prev_Energy_fx, 0); // setting to zero + //sts[n]->hBWE_FD->prev_frica_flag = sts[n]->hBWE_FD->prev_frica_flag; // fixed + //sts[n]->hBWE_FD->prev_td_energy = sts[n]->hBWE_FD->prev_td_energy_fx; // setting to zero + //sts[n]->hBWE_FD->prev_weight = fixedToFloat(sts[n]->hBWE_FD->prev_weight_fx, 15); // 6554; /*0.2 in Q15*/ + //sts[n]->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(sts[n]->prev_fb_ener_adjust_fx, 0); // setting to zero + //fixedToFloat_arr(sts[n]->hBWE_FD->mem_imdct_fx, sts[n]->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero } /* reset WB BWE buffers */ @@ -1546,16 +1797,16 @@ ivas_error ivas_mct_dec( IF(NE_16(sts[n]->last_extl, WB_BWE) && EQ_16(sts[n]->extl, WB_BWE) && sts[n]->hBWE_FD != NULL) { // set16_fx( sts[n]->hBWE_FD->L_old_wtda_swb_fx, 0, output_frame ); - fixedToFloat_arr(sts[n]->hBWE_FD->L_old_wtda_swb_fx, sts[n]->hBWE_FD->old_wtda_swb, 0, output_frame); + //fixedToFloat_arr(sts[n]->hBWE_FD->L_old_wtda_swb_fx, sts[n]->hBWE_FD->old_wtda_swb, 0, output_frame); IF(NE_16(sts[n]->last_extl, SWB_BWE) && NE_16(sts[n]->last_extl, FB_BWE)) { sts[n]->hBWE_FD->prev_mode = sts[n]->hBWE_FD->prev_mode; } - sts[n]->hBWE_FD->prev_Energy_wb = (float)sts[n]->hBWE_FD->prev_Energy_wb_fx; + //sts[n]->hBWE_FD->prev_Energy_wb = (float)sts[n]->hBWE_FD->prev_Energy_wb_fx; sts[n]->hBWE_FD->prev_L_swb_norm = sts[n]->hBWE_FD->prev_L_swb_norm; sts[n]->hBWE_FD->prev_flag = sts[n]->hBWE_FD->prev_flag; - fixedToFloat_arr(sts[n]->hBWE_FD->mem_imdct_fx, sts[n]->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero + //fixedToFloat_arr(sts[n]->hBWE_FD->mem_imdct_fx, sts[n]->hBWE_FD->mem_imdct, 0, L_FRAME48k); // setting to zero } /* reset TBE buffers */ @@ -1594,10 +1845,12 @@ ivas_error ivas_mct_dec( IF(EQ_16(sts[n]->bwidth, FB)) { +#if 0 IF(sts[n]->hBWE_FD != NULL) { sts[n]->hBWE_FD->prev_fb_ener_adjust = fixedToFloat(sts[n]->prev_fb_ener_adjust_fx, 0); } +#endif fixedToFloat_arr(sts[n]->hBWE_TD->fb_state_lpc_syn_fx, sts[n]->hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER); } } @@ -1656,7 +1909,6 @@ ivas_error ivas_mct_dec( hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_float[k] = (float)hCPE->hCoreCoder[n]->hTcxDec->FBTCXdelayBuf_32[k] / (1u << q); } } - IF(hCPE->hCoreCoder[n]->hTcxLtpDec) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; IF(hCPE->hCoreCoder[n]->hTcxLtpDec) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float)hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; if ((sts[n]->codec_mode == MODE1 && sts[n]->hTcxDec != NULL) && ((sts[n]->core == ACELP_CORE && !(sts[n]->bfi == 1 && sts[n]->con_tcx == 1)) || sts[n]->core == HQ_CORE)) @@ -1665,19 +1917,11 @@ ivas_error ivas_mct_dec( } - fixedToFloat_arr(sts[n]->old_synth_sw_fx, sts[n]->old_synth_sw, -2, 429); + //fixedToFloat_arr(sts[n]->old_synth_sw_fx, sts[n]->old_synth_sw, -2, 429); FOR(Word16 ind = 0; ind < 16; ind++) { sts[n]->mem_AR[ind] = sts[n]->mem_AR_fx[ind] / 2.56f; } - sts[n]->prev_tilt_code_dec = fixedToFloat(sts[n]->prev_tilt_code_dec_fx, Q15); - floatToFixed_arr(sts[n]->tilt_code_dec, sts[n]->tilt_code_dec_fx, Q15, 5); - floatToFixed_arr(sts[n]->old_synth_sw, sts[n]->old_synth_sw_fx, -2, 429); - sts[n]->prev_tilt_code_dec_fx = (Word16)floatToFixed(sts[n]->prev_tilt_code_dec, Q15); - FOR(Word16 ind = 0; ind < 16; ind++) { - sts[n]->mem_AR_fx[ind] = (Word16)(sts[n]->mem_AR[ind] * 2.56f); - } - fixedToFloat_arr(sts[n]->old_synth_sw_fx, sts[n]->old_synth_sw, 0, 429); } IF( hCPE->hStereoDft != NULL ) @@ -1692,7 +1936,6 @@ ivas_error ivas_mct_dec( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } @@ -2584,8 +2827,8 @@ static ivas_error ivas_mc_dec_reconfig( return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) @@ -3030,7 +3273,6 @@ static ivas_error ivas_mc_dec_reconfig( { fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_in, st->hTcxLtpDec->tcxltp_mem_in_float, 0, TCXLTP_MAX_DELAY ); fixedToFloat_arr( st->hTcxLtpDec->tcxltp_mem_out, st->hTcxLtpDec->tcxltp_mem_out_float, 0, L_FRAME48k ); - st->hTcxLtpDec->tcxltp_gain_post_prev_float = fixedToFloat( st->hTcxLtpDec->tcxltp_gain_post_prev, 0 ); } } #else diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 0101c5e49d6ace93964b49714bbf22a0c09a22ea..918081def1179a39bd8163c5ce7b9d632d6ba881 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -1733,7 +1733,7 @@ void ivas_mdct_core_invQ( st->Mode2_lp_gainp = float_to_fix(st->lp_gainp, Q16); st->hTcxLtpDec->tcxltp_gain = float_to_fix16(st->hTcxLtpDec->tcxltp_gain_float, Q15); //st->inv_gamma = FL2WORD16_SCALE(1 / st->gamma_float, 1); - f2me_16(st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e); + //f2me_16(st->last_gain_syn_deemph_float, &st->last_gain_syn_deemph, &st->last_gain_syn_deemph_e); f2me_16(st->last_concealed_gain_syn_deemph_float, &st->last_concealed_gain_syn_deemph, &st->last_concealed_gain_syn_deemph_e); f2me_16(st->hTcxDec->old_gaintcx_bfi_float, &st->hTcxDec->old_gaintcx_bfi, &st->hTcxDec->old_gaintcx_bfi_e); @@ -1743,7 +1743,7 @@ void ivas_mdct_core_invQ( st->hTcxDec->stepCompensate_float = me2f_16(st->hTcxDec->stepCompensate, st->hTcxDec->stepCompensate_e); st->hTcxDec->gainHelper_float = me2f_16(st->hTcxDec->gainHelper, st->hTcxDec->gainHelper_e); st->last_concealed_gain_syn_deemph_float = me2f_16(st->last_concealed_gain_syn_deemph, st->last_concealed_gain_syn_deemph_e); - st->last_gain_syn_deemph_float = me2f_16(st->last_gain_syn_deemph, st->last_gain_syn_deemph_e); + //st->last_gain_syn_deemph_float = me2f_16(st->last_gain_syn_deemph, st->last_gain_syn_deemph_e); st->hTcxDec->old_gaintcx_bfi_float = me2f_16(st->hTcxDec->old_gaintcx_bfi, st->hTcxDec->old_gaintcx_bfi_e); st->hTcxDec->cummulative_damping_tcx_float = fix16_to_float(st->hTcxDec->cummulative_damping_tcx, Q15); @@ -2252,8 +2252,9 @@ void ivas_mdct_core_reconstruct_fx( Scale_sig(st->hTcxDec->syn_OverlFB, L_FRAME_MAX / 2, sub(q_win, st->Q_syn)); Scale_sig(st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub(q_win, st->Q_syn)); Scale_sig(st->hHQ_core->old_out_fx, L_FRAME48k, sub(q_win, st->Q_syn)); - Scale_sig(synth_buf_fx, 3136, sub(-2, q_syn)); - Scale_sig(synth_bufFB_fx, 3136, sub(-2, q_syn)); + Scale_sig(synth_buf_fx, 3136, sub(q_win, q_syn)); + Scale_sig(synth_bufFB_fx, 3136, sub(q_win, q_syn)); + Scale_sig(st->syn, M + 1, q_win - st->Q_syn); FOR( k = 0; k < nSubframes[ch]; k++ ) { L_spec[ch] = st->hTcxCfg->tcx_coded_lines / nSubframes[ch]; @@ -2279,16 +2280,18 @@ void ivas_mdct_core_reconstruct_fx( IF ( EQ_16(bfi, 0) && st->hTonalMDCTConc != NULL ) { - TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synthFB_fx, L_frameTCX[ch] ); + Word16 synth_tmp[L_FRAME48k]; + Copy_Scale_sig(synthFB_fx, synth_tmp, st->hTonalMDCTConc->nSamples, 2); + TonalMDCTConceal_SaveTimeSignal( st->hTonalMDCTConc, synth_tmp, L_frameTCX[ch] ); } decoder_tcx_post_ivas_fx( st, synth_fx, synthFB_fx, NULL, bfi, MCT_flag ); Scale_sig(st->hTcxDec->syn_Overl_TDACFB, shr(L_FRAME_MAX, 1), sub(-1 - st->Q_syn, q_win)); Scale_sig(st->hTcxDec->syn_Overl_TDAC, shr(L_FRAME32k, 1), sub(-1 - st->Q_syn, q_win)); Scale_sig(st->hTcxDec->old_syn_Overl, shr(L_FRAME32k, 1), sub(-1 - st->Q_syn, q_win)); - Scale_sig(synth_buf_fx, 3136, sub(q_syn, -2)); - Scale_sig(synth_bufFB_fx, 3136, sub(q_syn, -2)); - Scale_sig(st->syn, M + 1, st->Q_syn + 1); + Scale_sig(synth_buf_fx, 3136, sub(q_syn, q_win)); + Scale_sig(synth_bufFB_fx, 3136, sub(q_syn, q_win)); + Scale_sig(st->syn, M + 1, st->Q_syn + 2); Scale_sig(st->hTcxDec->syn_OverlFB, shr(L_FRAME_MAX, 1), sub(st->Q_syn, q_win)); Scale_sig(st->hTcxDec->syn_Overl, shr(L_FRAME32k, 1), sub(st->Q_syn, q_win)); Scale_sig(st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub(st->Q_syn, q_win)); @@ -2367,7 +2370,7 @@ void ivas_mdct_core_reconstruct_fx( /* Postfiltering */ Word16 x_fx_16[1200]; - Copy_Scale_sig_32_16(x_fx[ch][0], x_fx_16, 1200, sub(0, q_x)); + Copy_Scale_sig_32_16(x_fx[ch][0], x_fx_16, st->L_frame, sub(0, q_x)); post_decoder_ivas_fx( st, synth_buf_fx, pit_gain_fx[ch], pitch[ch], x_fx_16, st->p_bpf_noise_buf ); diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 9fd193f193541c4d418d62b4e550940ea8db20f1..10fc518fe08eb5c23be7cc37dbe3cee5ad3b0cfc 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -368,8 +368,8 @@ ivas_error ivas_sba_dec_reconfigure( return error; } #if 1 /*Fixed to float */ - IF ( hTcBuffer->tc_buffer ) - fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); + if ( hTcBuffer->tc_buffer ) + fixedToFloat_arrL( hTcBuffer->tc_buffer_fx, hTcBuffer->tc_buffer, Q11, hTcBuffer->tc_buff_len ); IF( hSpar ) { FOR( Word16 in_ch = 0; in_ch < numch_in; in_ch++ ) diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index bcca73613a9d1f8737be5deef26eb81cc7d580f7..1cc78ad44e6337ac085a1617242f9dba64700447 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -293,6 +293,9 @@ typedef struct stereo_dft_dec_data_struct int16_t frame_sid; float scale; +#ifdef IVAS_FLOAT_FIXED + Word16 scale_fx; +#endif /* PLC on residual signal */ float res_mem[STEREO_DFT_RES_BW_MAX]; @@ -1228,10 +1231,10 @@ typedef struct ivas_masa_ism_data_structure #ifdef IVAS_FLOAT_FIXED Word32 **delayBuffer_fx; Word16 ismPreprocMatrix_fx[2][2][CLDFB_NO_CHANNELS_MAX]; - Word16 eneMoveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; - Word16 enePreserveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; - Word16 preprocEneTarget_fx[CLDFB_NO_CHANNELS_MAX]; - Word16 preprocEneRealized_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 eneMoveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; + Word32 enePreserveIIR_fx[2][CLDFB_NO_CHANNELS_MAX]; + Word32 preprocEneTarget_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 preprocEneRealized_fx[CLDFB_NO_CHANNELS_MAX]; #endif int16_t delayBuffer_size; diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 352115551355a69f31f152b386581c8370b7ea87..93df999706b0d720a73fd816710dc83129340e91 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -49,15 +49,23 @@ *-------------------------------------------------------------------*/ #define A_GFILT 0.8f /* LP-filter coefficient for coherence and sidegain */ +#ifdef IVAS_FLOAT_FIXED +#define A_GFILT_FX (Word16)(0x6666) /* LP-filter coefficient for coherence and sidegain */ +#define ONE_MINUS_A_GFILT_FX (Word16)(0x199A) /* LP-filter coefficient for coherence and sidegain */ +#endif #define SKIP_XFADE_FRAMES 2 /* DTX/CNG */ #define MAX_K 50.0f +#define ONE_BY_MAX_K (Word16)(0x028F) #define STEREO_TD_PS_CORR_FILT 0.8f #define STEREO_TD_PS_CORR_FILT_FX 1717986918 #define STEREO_TD_PS_CORR_FILT_Q31 1717986944 #define ONE_MINUS_STEREO_TD_PS_CORR_FILT_Q31 429496704 #define MAX_XFADE 50.0f +#ifdef IVAS_FLOAT_FIXED +#define MAX_XFADE_FX 50 +#endif #define CM_INIT 50 #define CORR_INIT 8 #define SID_INIT 6 @@ -652,6 +660,716 @@ static void stereo_dft_generate_comfort_noise( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------- + * stereo_dft_generate_comfort_noise_fx() + * + * Generate the comfort noise based on the target noise level for the CLDFB part + *-------------------------------------------------------------------*/ + +static void stereo_dft_generate_comfort_noise_fx( + STEREO_DFT_DEC_DATA_HANDLE hStereoDft, /* i/o: DFT Stereo decoder handle */ + STEREO_CNG_DEC_HANDLE hStereoCng, /* i/o: Stereo CNG data structure */ + const Word16 last_element_mode, /* i : last element mode */ + Decoder_State *st, /* i/o: Core coder decoder state */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + Decoder_State *st1, /* i/o: Core coder decoder state secondary channel */ + const Word16 targetGain, /* i : ICA target gain */ + const Word16 chan, /* i : channel number */ + const Word16 output_frame, /* i : output frame size */ + Word16 q_dft /* i : Q of DFT */ +) +{ + Word16 i, j, k; + Word32 *ptr_level, *ptr_shb, *ptr_r, *ptr_i; + HANDLE_FD_CNG_COM hFdCngCom; + Word16 numSlots; + Word16 scale, inv_scale, tmp_16; + Word32 lp_noise; + Word32 tmp, enr; + Word16 q_enr; + Word32 shb_shape[L_FRAME16k]; + Word16 q_shb_shape[L_FRAME16k]; + Word32 *ptr0, *ptr1, *ptr2; + Word16 *ptr_q_shb; + Word16 dmpf[M + 2], Atmp[M + 2]; + Word32 cngNoiseLevel_upd[L_FRAME16k], cngNoiseLevel_hist[L_FRAME16k - 2]; + Word32 *ptr_tmp, *ptr_cng; + Word32 E0, E1; + Word16 b, q_cngNoiseLevel_upd, q_cngNoiseLevel; + Word32 *pSideGain; + Word16 gamma; + Word16 c; + Word16 scaleMS; + Word16 scaleAvg; + Word16 LR_ratio; + Word16 factor; + Word16 alpha; + Word32 ftmp; + Word16 trigo_dec[STEREO_DFT32MS_N_16k / 2 + 1]; + const Word16 *pTrigo; + Word16 trigo_step; + Word16 addl_guard_bits; + + /* + * The additional guard bits data is added to tackle very small shb_cng_gain_fx_32. + * One additional guard bit is added for every 6dB post -12dB. + * -12dB in Q11 is (Word32)0xFFFFA000. + * The guard bits are calculated by converting the power of 10 exponent to power of 2 exponent. + */ + addl_guard_bits = s_max(1, shr(extract_l(L_shr(Mpy_32_16_1(L_sub((Word32)0xFFFFA000, st->hTdCngDec->shb_cng_gain_fx_32), (Word16)0x2A85), Q11)), 1)); + + move16(); + + hFdCngCom = st->hFdCngDec->hFdCngCom; + + push_wmops( "DFT_CNG" ); + + set_val_Word16( dmpf, 0, M + 2 ); + set_val_Word16( Atmp, 0, M + 2 ); + + set_val_Word32( DFT[chan], 0, STEREO_DFT_BUF_MAX ); + + enr = 0; /* Eliminates compiler warning. They are always set before they are used */ + move32(); + q_enr = 0; + move16(); + E0 = 0; + move32(); + E1 = 0; + move32(); + lp_noise = 0; + move32(); + q_cngNoiseLevel_upd = 0; + move16(); + q_cngNoiseLevel = 0; + move16(); + + IF ( EQ_16(chan , 0) ) + { + pSideGain = hStereoDft->side_gain_fx + STEREO_DFT_NBDIV * STEREO_DFT_BAND_MAX; + FOR ( b = 0; b < hStereoDft->nbands; b++ ) + { + IF ( EQ_16(hStereoCng->xfade_frame_counter , 0) ) + { + hStereoDft->g_state_fx[b] = extract_h(*pSideGain++); + move16(); + } + ELSE + { + hStereoDft->g_state_fx[b] = add(mult(ONE_MINUS_A_GFILT_FX , extract_h(*pSideGain++)), mult(A_GFILT_FX , hStereoDft->g_state_fx[b])); + move16(); + } + + IF ( hStereoCng->first_SID ) + { + IF ( hStereoCng->first_SID_after_TD ) + { + hStereoCng->cm_fx[b] = extract_h(Mpy_32_32(hStereoCng->c_LR_LT_fx , hStereoCng->c_LR_LT_fx)); + move16(); + } + ELSE + { + hStereoCng->cm_fx[b] = hStereoCng->coh_fx[b]; + move16(); + } + } + ELSE IF ( LT_16(hStereoCng->nr_dft_frames , CM_INIT) && LT_16(hStereoCng->nr_sid_frames , SID_INIT) ) + { + IF ( GT_16(hStereoCng->nr_corr_frames , CORR_INIT) ) + { + hStereoCng->cm_fx[b] = extract_h(Mpy_32_32(hStereoCng->c_LR_LT_fx , hStereoCng->c_LR_LT_fx)); + move16(); + } + ELSE + { + hStereoCng->cm_fx[b] = add(mult( ONE_MINUS_A_GFILT_FX , hStereoCng->coh_fx[b]) , mult(A_GFILT_FX , hStereoCng->cm_fx[b])); + move16(); + } + } + ELSE + { + hStereoCng->cm_fx[b] = add(mult(ONE_MINUS_A_GFILT_FX , hStereoCng->coh_fx[b]), mult(A_GFILT_FX , hStereoCng->cm_fx[b])); + move16(); + } + } + + IF ( hStereoCng->first_SID_after_TD ) + { + Word16 q_div, q_sqrt; + scaleAvg = 0; move16(); + FOR ( b = 0; b < hStereoDft->nbands; b++ ) + { + Word32 tmp_n, tmp_d; + Word16 sqrt_res; + IF ( LT_16(hStereoCng->cm_fx[b], (Word32)(0x7333)) ) + { + gamma = hStereoCng->cm_fx[b]; + move16(); + gamma = BASOP_Util_Divide1616_Scale(gamma , sub( MAX_16 , gamma ), &q_div); + tmp_16 = Sqrt16(gamma, &q_div); + gamma = Sqrt16( add(gamma, sub(MAX_16, mult(hStereoDft->g_state_fx[b], hStereoDft->g_state_fx[b]))), &q_sqrt); + gamma = shl(gamma, sub(q_sqrt, q_div)); // Bring both gamma and tmp to same Q i.e., q_div. + gamma = shl(sub(gamma, tmp_16), q_div); // Apply appropriate left shift on the result. + } + ELSE + { + gamma = 0; move16(); + } + + LR_ratio = extract_h(tdm_ratio_tabl_fx[hStereoCng->last_tdm_idx]); + c = BASOP_Util_Divide3232_Scale( + L_add( L_mult(add( ONE_IN_Q13 , shr(hStereoDft->g_state_fx[b], 2) ) , + add( ONE_IN_Q13 , shr(hStereoDft->g_state_fx[b], 2) )), + L_shr(L_mult(gamma , gamma), 2)), + L_add( Mpy_32_32(sub( ONE_IN_Q13 , shr(hStereoDft->g_state_fx[b], 2) ) , + sub( ONE_IN_Q13 , shr(hStereoDft->g_state_fx[b], 2) )), + L_shr(L_mult(gamma , gamma), 2)), + &q_div); + q_sqrt = q_div; move16(); + sqrt_res = Sqrt16(mult(c , hStereoCng->cm_fx[b]), &q_sqrt ); + // Add 1 to q_sqrt to account for multiplication with 2.0 in float computation. + q_sqrt = add(q_sqrt, 1); + tmp_n = L_add(L_add(L_shl(1, sub(Q15, q_div)), c) , L_shr(L_deposit_l(sqrt_res), sub(q_div, q_sqrt))); + q_sqrt = q_div; move16(); + sqrt_res = Sqrt16(mult(c, hStereoCng->cm_fx[b]), &q_sqrt); + tmp_d = L_shl(L_add( L_shl(L_deposit_l(mult(c , mult(LR_ratio , LR_ratio))), q_div), + L_add(mult(mult(sub( MAX_16 , LR_ratio ) , sub( MAX_16 , LR_ratio )) , mult(targetGain , targetGain)), + L_shl(L_deposit_l(mult(mult(LR_ratio , sub( MAX_16 , LR_ratio )) , mult(targetGain , sqrt_res))), add(1, q_sqrt)))), // add(1, q_sqrt) to account for multiplication with 2 and also to maintain uniform q. + 2); + scaleMS = BASOP_Util_Divide3232_Scale( tmp_n, tmp_d, &q_div); + q_sqrt = q_div; move16(); + scaleMS = Sqrt16( scaleMS, &q_sqrt ); + scaleAvg = add(scaleAvg, shr(scaleMS, sub(Q15, q_sqrt))); + } + scaleAvg = BASOP_Util_Divide1616_Scale(scaleAvg , hStereoDft->nbands, &q_div); + hStereoDft->scale_fx = shl(scaleAvg, q_div); + } + } + + IF ( EQ_16(st->cng_type , LP_CNG) ) + { + Word16 q_sqrt, q_div, q_inv_sqrt, rshift_shb = 0, rshift_cng; + Word32 min_val; + move16(); + set_val_Word32( cngNoiseLevel_upd, 0, st->L_frame ); + + /* Deemphasis */ + dmpf[0] = MAX_16; move16(); + dmpf[1] = negate(st->preemph_fac); move16(); + Copy( st->Aq_cng, Atmp, M + 1 ); + conv_fx_32( Atmp, dmpf, cngNoiseLevel_upd, M + 2 ); + + IF ( EQ_16(st->L_frame , L_FRAME) ) + { + pTrigo = hStereoDft->dft_trigo_12k8_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_12k8_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); + } + ELSE + { + pTrigo = hStereoDft->dft_trigo_16k_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); + } + + FOR ( i = 0; i < shr(st->L_frame , 2); i++ ) + { + trigo_dec[i] = pTrigo[i * trigo_step]; + move16(); + trigo_dec[sub(shr(st->L_frame, 1) , i)] = pTrigo[i * trigo_step]; + move16(); + } + trigo_dec[shr(st->L_frame , 2)] = pTrigo[shr(st->L_frame , 2) * trigo_step]; + move16(); + + rshift_cng = getScaleFactor32(cngNoiseLevel_upd, st->L_frame); + rshift_cng = sub(find_guarded_bits_fx(st->L_frame), rshift_cng); + /* + * The guardbits calculated here are not sufficient for all cases. + * Due to the gain values like shb_cng_gain and other things in the ensuing code blocks, + * additional guard bits have to be added. The choice based on existing test vector set is Q2 + */ + rshift_cng = add(rshift_cng, addl_guard_bits); + v_shr_32(cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, rshift_cng); + // Input Q to fft will be Q30 - rshift. + rfft_fx(cngNoiseLevel_upd, trigo_dec, st->L_frame, -1 ); + //v_shr_32(cngNoiseLevel_upd, cngNoiseLevel_upd, st->L_frame, negate(rshift)); + + /* Compute 1/|A| */ + ptr0 = cngNoiseLevel_upd; + ptr1 = ptr0 + 2; + ptr2 = ptr1 + 1; + assert( st->lp_ener_fx > 0 ); + // lp_ener_fx will be in Q6 at this point. + // So applying appropriate left shift on the denominator. + factor = shr(BASOP_Util_Divide3232_Scale(st->lp_ener_fx , L_shl(st->L_frame, Q6), &q_div), 1); /* fixed factor in the loop below */ + factor = Sqrt16( factor , &q_div); + // there is multiplication with 2.0 that has to be applied on the factor and + // a left shift of q_div as shown in the below two steps. + //factor = shl(factor, add(q_div, 1)); + //q_div = 0; move16(); + // The left shift of q_div and 1 (because of multiplication factor 2.0) is handled below. + // by adjusting q_inv_sqrt. + minimum_abs32_fx(ptr0, st->L_frame, &min_val); + q_inv_sqrt = sub(sub(Q31, norm_l(L_abs(min_val))), add(q_div, 1)); + FOR ( i = 0; i < shr(st->L_frame, 1) - 1; i++ ) + { + //if ((*ptr1 == 0) && (*ptr2 == 0)) + // assert(0); + //assert( (*ptr1 != 0) || (*ptr2 != 0)); + IF (norm_l(*ptr1) > rshift_cng && norm_l(*ptr2) > rshift_cng) + { + ftmp = Madd_32_32(Mpy_32_32(L_shl(*ptr1, rshift_cng) , L_shl(*ptr1, rshift_cng)) , L_shl(*ptr2, rshift_cng) , L_shl(*ptr2, rshift_cng)); + q_sqrt = Q2; + } + ELSE + { + ftmp = Madd_32_32(Mpy_32_32(*ptr1 , *ptr1) , *ptr2 , *ptr2); + q_sqrt = sub(Q31, sub(shl(sub(Q30, rshift_cng), 1) , Q31)); + } + IF (EQ_32(ftmp , 0)) + { + ftmp = EPSILON_FX; move32(); + q_sqrt = s_max(0, q_sqrt); + } + tmp = ISqrt32(ftmp, &q_sqrt); + tmp = L_shl(tmp, sub(q_sqrt, q_inv_sqrt)); + tmp = Mpy_32_16_1(tmp, factor); + tmp = L_shl(tmp, add(sub(sub(Q30, rshift_cng), sub(Q31, q_sqrt)), add(q_div, 1))); + *ptr0++ = tmp; move32(); + ptr1 += 2; + ptr2 += 2; + } + // q_div + 1 has to be added back to q_inv_sqrt. + q_cngNoiseLevel_upd = sub(Q30, rshift_cng); + + IF ( GT_16(sub(s_min( output_frame, L_FRAME32k ), hFdCngCom->stopFFTbin) , 0) ) + { + /* Transform shb LP spectrum */ + set_val_Word32( shb_shape, 0, L_FRAME16k ); + set_val_Word16( q_shb_shape, 0, L_FRAME16k); + Copy_Scale_sig_16_32( st->hTdCngDec->shb_lpcCNG_fx, shb_shape, LPC_SHB_ORDER + 1, Q15); + + IF ( NE_16(st->L_frame , L_FRAME16k) ) + { + pTrigo = hStereoDft->dft_trigo_16k_fx; + trigo_step = STEREO_DFT_TRIGO_SRATE_16k_STEP * STEREO_DFT_TRIGO_DEC_STEP; + move16(); + FOR ( i = 0; i < L_FRAME16k / 4; i++ ) + { + trigo_dec[i] = pTrigo[i * trigo_step]; + move16(); + trigo_dec[L_FRAME16k / 2 - i] = pTrigo[i * trigo_step]; + move16(); + } + trigo_dec[L_FRAME16k / 4] = pTrigo[L_FRAME16k / 4 * trigo_step]; + move16(); + } + + rshift_shb = getScaleFactor32(shb_shape, L_FRAME16k); + rshift_shb = sub(find_guarded_bits_fx(L_FRAME16k), rshift_shb); + /* + * The guardbits calculated here are not sufficient for all cases. + * Due to the gain values like shb_cng_gain and other things in the ensuing code blocks, + * additional guard bits have to be added. The choice based on existing test vector set is Q2 + */ + rshift_shb = add(rshift_shb, addl_guard_bits); + v_shr_32(shb_shape, shb_shape, L_FRAME16k, rshift_shb); + rfft_fx( shb_shape, trigo_dec, L_FRAME16k, -1 ); + //v_shr_32(shb_shape, shb_shape, L_FRAME16k, negate(rshift)); + + /* Compute 1/|A| */ + enr = Madd_32_32(Mpy_32_32(L_shl(shb_shape[0], addl_guard_bits), L_shl(shb_shape[0], addl_guard_bits)), + L_shl(shb_shape[1], addl_guard_bits) , L_shl(shb_shape[1], addl_guard_bits)); + q_enr = add(sub(shl(sub(Q30, rshift_shb), 1), Q31), shl(addl_guard_bits, 1)); + IF (EQ_32(enr , 0)) + { + enr = EPSILON_FX; move32(); + q_enr = s_max(0, q_enr); + } + ptr0 = shb_shape; + ptr1 = ptr0 + 2; + ptr2 = ptr1 + 1; + + FOR ( i = 0; i < L_FRAME16k / 2 - 1; i++ ) + { + Word16 q_shift = sub(shl(sub(Q30, rshift_shb), 1), Q31); + //assert((*ptr1 != 0) || (*ptr2 != 0)); + ftmp = Madd_32_32( Mpy_32_32(L_shl(*ptr1, addl_guard_bits) , L_shl(*ptr1, addl_guard_bits)) , + L_shl(*ptr2, addl_guard_bits) , L_shl(*ptr2, addl_guard_bits)); + q_shift = add(q_shift, shl(addl_guard_bits, 1)) ; + IF(EQ_32(ftmp, 0)) + { + ftmp = EPSILON_FX; move32(); + q_shift = s_max(0, q_shift); + } + ftmp = L_deposit_l(BASOP_Util_Divide3232_Scale(L_sub(L_shl(Q1, q_shift), 1), ftmp, &q_div)); + ftmp = L_shl(ftmp, sub(q_div, sub(Q15, q_shift))); + /* in float: + both a = "div"=(1/(x^2+y^2) and sqrt(a) is used and summed up in the same loop. + + in BASOP: + sum up using inv_sqrt( *ptr1 * *ptr1 + *ptr2 * *ptr2 ), in this loop + and then sum up enr = sum( *ptr0 * *ptr0 ), in a subsequent MAC loop */ + enr = L_add(enr, ftmp); + q_div = sub(Q31, q_shift); + ftmp = Sqrt32( ftmp, &q_div ); + // Reduce the Q of shb_shape back to its original Q i.e., Q30 - rshift + ftmp = L_shr(ftmp, sub(sub(Q31, q_div), sub(Q30, rshift_shb))); + *ptr0++ = ftmp; move32(); + ptr1 += 2; + ptr2 += 2; + } + } + + /* Update CNG noise level from MS noise estimation */ + Copy32( st->hFdCngDec->bandNoiseShape, cngNoiseLevel_hist, sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand) ); + ptr_cng = cngNoiseLevel_hist; + FOR ( i = 0; i < shr(sub( st->last_L_frame , hFdCngCom->startBand ) , 1); i++ ) + { + tmp = *( cngNoiseLevel_hist + i * 2 ); move32(); + tmp = L_add(tmp, *( cngNoiseLevel_hist + i * 2 + 1 )); + *ptr_cng++ = L_shr(tmp, 1); move32(); + } + + IF ( last_element_mode == IVAS_CPE_TD && chan == 0 && hStereoCng->xfade_frame_counter == 0 && !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + { + ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; + ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; + FOR ( i = 0; i < shr(sub( st->last_L_frame , hFdCngCom->startBand ) , 1); i++ ) + { + E0 = L_add(E0, *ptr_cng++); + E1 = Madd_32_32(E1, ( *ptr_tmp ), ( *ptr_tmp )); + ptr_tmp++; + } + + tmp_16 = BASOP_Util_Divide3232_Scale(E0 , E1, &q_div); + tmp_16 = Sqrt16( tmp_16, &q_div); + IF ( LT_16(tmp_16 , shr(MAX_16, q_div)) ) + { + tmp_16 = shl(tmp_16, q_div); + hStereoCng->xfade_length = sub( MAX_XFADE_FX , extract_l(L_shr(imult3216(MAX_XFADE_FX , tmp_16), Q15))); + } + ELSE + { + Word16 q_inv; + tmp_16 = Invert16(tmp_16, &q_inv); + tmp_16 = shl(tmp_16, add(q_inv, q_div)); + hStereoCng->xfade_length = sub( MAX_XFADE_FX , extract_l(L_shr(imult3216(MAX_XFADE_FX , tmp_16), Q15))); + } + } + + IF ( LT_16(hStereoCng->xfade_frame_counter , hStereoCng->xfade_length) ) + { + ptr_cng = cngNoiseLevel_hist + hFdCngCom->startBand; + ptr_tmp = cngNoiseLevel_upd + hFdCngCom->startBand; + FOR ( i = 0; i < ( st->last_L_frame - hFdCngCom->startBand ) / 2; i++ ) + { + tmp_16 = BASOP_Util_Divide1616_Scale(hStereoCng->xfade_frame_counter , hStereoCng->xfade_length, &q_div); + tmp_16 = shl(tmp_16, q_div); + tmp = Sqrt32( *ptr_cng++, &q_sqrt ); + tmp = L_shl(tmp, q_sqrt); + *ptr_tmp = L_add(Mpy_32_16_1(*ptr_tmp, tmp_16), Mpy_32_16_1(Mpy_32_16_1(tmp, sub( MAX_16 , tmp_16 )) , hStereoDft->scale_fx)); + move32(); + ptr_tmp++; + } + } + + FOR ( k = 0; k < STEREO_DFT_NBDIV; k++ ) + { + Word16 shift_val = sub(Q31, q_cngNoiseLevel_upd); + /* low band */ + ptr_level = cngNoiseLevel_upd; + ptr_r = DFT[chan] + hFdCngCom->startBand + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + scale = shr(output_frame , 1); + + FOR ( i = 0; i < shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1); i++ ) + { + /* Real part in FFT bins */ + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft ); + // the Q factor of ptr_level is q_cngNoiseLevel_upd + // To ensure the result of the multiplication is with optimal precision + // apply left shift on the input data and use it for multiplication + // result of multiplication will be in same Q as ptr_r buffer + tmp = imult3216(( *ptr_r ), scale); + IF (GE_16(norm_l(tmp), shift_val)) + { + ( *ptr_r ) = Mpy_32_32(L_shl(tmp, shift_val), *ptr_level); move32(); + } + ELSE + { + ( *ptr_r ) = L_shl(Mpy_32_32(tmp, *ptr_level), shift_val); move32(); + } + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft ); + tmp = imult3216(( *ptr_i ) , scale); move32(); + IF (GE_16(norm_l(tmp), shift_val)) + { + ( *ptr_i ) = Mpy_32_32(L_shl(tmp, shift_val), *ptr_level); + } + ELSE + { + ( *ptr_i ) = L_shl(Mpy_32_32(tmp, *ptr_level), shift_val); + } + ptr_i += 2; + ptr_level++; + } + + IF ( GT_16(sub(s_min( output_frame, L_FRAME32k ) , hFdCngCom->stopFFTbin) , 0) ) + { + Word16 q_res = 0; + Word32 scale_32; + /* high band generation, flipped spectrum */ + assert( enr != 0 ); + // 10 ^ (0.1 * st->hTdCngDec->shb_cng_gain) + // Above expression equivalent to 2 ^ (3.321928094 * 0.1 * st->hTdCngDec->shb_cng_gain) + // 3.321928094 * 0.1 = 0.3321928094 + // st->hTdCngDec->shb_cng_gain_fx_32 Q is 11 + scale_32 = BASOP_util_Pow2( Mpy_32_16_1(st->hTdCngDec->shb_cng_gain_fx_32, (Word16)0x2A85), Q31 - Q11, &q_res); + //Q of scale_32 is Q31 - q_res, Q of enr is + //scale_32 = L_shl(scale_32, sub( q_enr, sub(Q31, q_res))); + q_div = 0; move16(); + scale = BASOP_Util_Divide3232_Scale( scale_32, enr, &q_div); + //q_res = add(q_div, sub( q_enr, sub(Q31, q_res))); move16(); + q_res = sub(Q15, add(sub(Q15, q_div), sub(sub(Q31, q_res), q_enr))); move16(); + //q_div = sub(Q15, q_res); move16(); + q_div = q_res; + inv_scale = ISqrt16( scale, &q_res); + scale = Sqrt16(scale, &q_div); + ptr_shb = shb_shape + L_FRAME16k / 2 - 1; + ptr_q_shb = q_shb_shape + L_FRAME16k / 2 - 1; + /* Averaging for Nyquist frequency */ + tmp = Mpy_32_16_1(cngNoiseLevel_upd[sub(shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1) , 1)] , inv_scale); + // q of cngNoiseLevel_upd is Q16. + // ptr_shb will be in Q30 - rshift. tmp is in Q16(Q15 + 1 (for the 0.5 in multiplication)) - q_res, Applying appropriate shift on tmp + q_res = sub(sub(Q30, rshift_cng), sub(Q16, q_res)); + IF (LT_16(q_res, norm_l(tmp))) + { + tmp = L_shl(tmp, q_res); + q_res = 0; move16(); + } + *ptr_q_shb = q_res; move16(); + + // Bring both ptr_shb and ptr_shb - 1 to the same Q. + *ptr_shb = L_shr(L_add(tmp, L_shr(*( ptr_shb - 1 ), sub(q_res, *(ptr_q_shb - 1)))), 1); move32(); + ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + + FOR ( i = 0; i < ( min( output_frame, hFdCngCom->regularStopBand * 16 ) - hFdCngCom->stopFFTbin ) / 2; i++ ) + { + /* Real part in FFT bins */ + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft); + //ptr_shb will be in Q30 - rshift at this point. So apply left shift by 1 to compensate Mpy_32_32 right shift.. + ( *ptr_r ) = L_shl(Mpy_32_32(L_shl(*ptr_r, add(1, *ptr_q_shb)), *ptr_shb), rshift_shb); move32(); + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft); + ( *ptr_i ) = L_shl(Mpy_32_32(L_shl(*ptr_i, add(1, *ptr_q_shb)), *ptr_shb), rshift_shb); move32(); + ptr_i += 2; + ptr_shb--; + } + + /* rescale */ + //scale = L_shr(imult3216(scale, output_frame) , 1); + //multiplication with shr(output_frame, 1) is carried out below. + ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + FOR ( i = 0; i < shr(sub( s_min( output_frame, shl(hFdCngCom->regularStopBand , 4) ) , hFdCngCom->stopFFTbin ) , 1); i++ ) + { + ( *ptr_r ) = imult3216(L_shl(Mpy_32_16_1(*ptr_r, scale), q_div), shr(output_frame, 1)); + move32(); + ( *ptr_i ) = imult3216(L_shl(Mpy_32_16_1(*ptr_i, scale), q_div), shr(output_frame, 1)); + move32(); + ptr_r += 2; + ptr_i += 2; + } + } + } + + /* Expand cngNoiseLevel_flt from 0-159 to 0-318, compute noise level */ + lp_noise = 0; move32(); + ptr_level = hFdCngCom->cngNoiseLevel + sub(sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand) , 1); + ptr_tmp = cngNoiseLevel_upd + sub(shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1) , 1); + rshift_cng = sub(hFdCngCom->q_cngNoiseLevel, sub(shl(q_cngNoiseLevel_upd, 1), Q31)); + FOR ( i = 0; i < shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1); i++ ) + { + IF (norm_l(*ptr_tmp) >= rshift_cng) + { + *ptr_level-- = Mpy_32_32(L_shl(*ptr_tmp, rshift_cng) , *ptr_tmp); + move32(); + } + ELSE + { + *ptr_level-- = L_shl(Mpy_32_32(*ptr_tmp, *ptr_tmp), rshift_cng); + move32(); + } + + ptr_tmp--; + *ptr_level = *( ptr_level + 1 ); move32(); + lp_noise = L_add(lp_noise, L_shl(*ptr_level--, 1)); + } + //q_cngNoiseLevel = sub(shl(q_cngNoiseLevel_upd, 1), Q31); + //hFdCngCom->q_cngNoiseLevel = q_cngNoiseLevel; move16(); + } + ELSE + { + /* FD-CNG */ + IF ( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) ) + { + IF ( hStereoCng->xfade_frame_counter <= MAX_K && hStereoCng->last_act_element_mode == IVAS_CPE_TD && chan == 0 ) + { + /* Fade MS -> SID/MS */ + j = 0; move16(); + FOR ( k = 0; k < ( hFdCngCom->nFFTpart - 2 ); k++ ) + { + Word16 q_div; + factor = BASOP_Util_Divide3232_Scale(( hFdCngCom->sidNoiseEstLp[k] + DELTA_FX ) , ( st->hFdCngDec->partNoiseShape[k] + DELTA_FX ), &q_div); + factor = s_min( add(hStereoDft->scale_fx , extract_l(Mpy_32_16_1(L_mult(sub( factor , hStereoDft->scale_fx ) , hStereoCng->xfade_frame_counter), ONE_BY_MAX_K))), factor); + FOR ( ; j <= hFdCngCom->part[k]; j++ ) + { + hFdCngCom->cngNoiseLevel[j] = Mpy_32_16_1(st->hFdCngDec->bandNoiseShape[j] , factor); + move32(); + } + } + } + } + scale = shr(output_frame, 1); + numSlots = shr(hFdCngCom->numSlots , 2); + FOR ( k = 0; k < STEREO_DFT_NBDIV; k++ ) + { + ptr_level = hFdCngCom->cngNoiseLevel; + ptr_r = DFT[chan] + hFdCngCom->startBand + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + q_cngNoiseLevel = hFdCngCom->q_cngNoiseLevel; + FOR ( i = 0; i < shr(sub( hFdCngCom->stopFFTbin , hFdCngCom->startBand ) , 1); i++ ) + { + Word16 q_sqrt; + /* Real part in FFT bins */ + tmp = *ptr_level++; move32(); + tmp = L_add(tmp, *ptr_level++); + tmp = L_shr(tmp, 1); + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft); + q_sqrt = sub(Q31 , q_cngNoiseLevel); + tmp = Sqrt32( tmp, &q_sqrt ); + tmp = Mpy_32_32(*(ptr_r), tmp); + tmp = imult3216(tmp, scale); + ( *ptr_r ) = L_shl(tmp, q_sqrt); move32(); + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft); + ( *ptr_i ) = Mpy_32_32((*ptr_i), tmp); move32(); + ptr_i += 2; + } + ptr_level = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; + ptr_r = DFT[chan] + hFdCngCom->stopFFTbin + k * STEREO_DFT32MS_N_MAX; + ptr_i = ptr_r + 1; + FOR ( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ ) + { + FOR ( i = 0; i < numSlots; i++ ) + { + Word16 q_sqrt; + /* Real part in FFT bins */ + rand_gauss_fx( ptr_r, &st->hTdCngDec->cng_seed, q_dft); + tmp = Mpy_32_16_1(Sqrt32( *ptr_level, &q_sqrt ) , scale); + ( *ptr_r ) = Mpy_32_32(*ptr_r, tmp); move32(); + ptr_r += 2; + /* Imaginary part in FFT bins */ + rand_gauss_fx( ptr_i, &st->hTdCngDec->cng_seed, q_dft); + ( *ptr_i ) = Mpy_32_32(*ptr_i, tmp); move32(); + ptr_i += 2; + } + ptr_level++; + } + } + + /* Compute noise level */ + lp_noise = 0; move32(); + ptr_level = hFdCngCom->cngNoiseLevel; + FOR ( i = 0; i < sub(hFdCngCom->stopFFTbin , hFdCngCom->startBand); i++ ) + { + lp_noise = L_add(lp_noise, *ptr_level++); + } + } + + IF ( hStereoCng->last_act_element_mode == IVAS_CPE_TD && chan > 0 ) + { + Word32 log_lp_noise = L_add(L_shl(sub(Q31, hFdCngCom->q_cngNoiseLevel), Q25), BASOP_Util_Log2( lp_noise + DELTA_FX )); + // log10(x) is computed as log2(x) * log10(2) + // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 + // Hence the 16-bit constant log10(2) will be stored in Q13 + log_lp_noise = Mpy_32_16_1(log_lp_noise , (Word16)0x09A2); + st1->lp_noise = L_add(Mpy_32_16_1(st1->lp_noise, (Word16)(0x7333)) , log_lp_noise); move32(); + } + ELSE IF ( EQ_16(chan , 0) ) + { + Word16 q_lp_noise = 0;//st->hFdCngDec->q_lp_noise; // to be populated appropriately. + Word32 log_lp_noise = L_add(L_shl(sub(Q31, hFdCngCom->q_cngNoiseLevel), Q25), BASOP_Util_Log2( lp_noise + DELTA_FX )); + move16(); + // log10(x) is computed as log2(x) * log10(2) + // log_lp_noise at this stage is in Q25. where as the structure value is in Q23 + // Hence the 16-bit constant log10(2) will be stored in Q13 + log_lp_noise = Mpy_32_16_1(log_lp_noise , (Word16)0x09A2); + st->hFdCngDec->lp_noise = L_add(Mpy_32_16_1(st->hFdCngDec->lp_noise, (Word16)(0x7333)), log_lp_noise); move32(); + st->lp_noise = st->hFdCngDec->lp_noise; move32(); + st->hFdCngDec->hFdCngCom->flag_noisy_speech = (Word16)LT_32(L_shr(L_sub( st->hFdCngDec->lp_speech , st->hFdCngDec->lp_noise ), q_lp_noise) , 28); move16(); + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add( Mpy_32_32( Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx ), + imult3216(Q31_0_01, st->hFdCngDec->hFdCngCom->flag_noisy_speech)); move32(); + } + + IF ( EQ_16(chan , 0) && LE_32(st->core_brate , SID_2k40) ) + { + /* update smoothed periodogram used by stereo CNA in SID and NO_DATA frames from cngNoiseLevel_flt */ + FOR ( i = hFdCngCom->startBand; i < hFdCngCom->stopFFTbin; i++ ) + { + Word16 l_shift_val = sub(st->hFdCngDec->q_smoothed_psd, hFdCngCom->q_cngNoiseLevel); + move16(); + ftmp = hFdCngCom->cngNoiseLevel[i - hFdCngCom->startBand]; + move32(); + IF ( !st->hFdCngDec->first_cna_noise_updated ) + { + /* very first update */ + alpha = 0; + move16(); + } + ELSE + { + alpha = (Word16)(0x799A); + move16(); + IF ( GT_32(st->hFdCngDec->smoothed_psd_fx[i] , 0) && GT_32(Mpy_32_16_1(ftmp, (Word16)0x3333), st->hFdCngDec->smoothed_psd_fx[i]) ) + { + /* prevent abrupt upward update steps */ + ftmp = L_add(L_shl(st->hFdCngDec->smoothed_psd_fx[i], 2), L_shr(st->hFdCngDec->smoothed_psd_fx[i], 1)); + l_shift_val = 0; move16(); + } + ELSE IF ( LT_32(ftmp , L_shr(st->hFdCngDec->smoothed_psd_fx[i], l_shift_val)) ) + { + /* faster downward updates */ + alpha = (Word16)(0x599A); + move16(); + } + } + + /* smoothing */ + st->hFdCngDec->smoothed_psd_fx[i] = L_add(Mpy_32_16_1(st->hFdCngDec->smoothed_psd_fx[i], alpha) , L_shl(Mpy_32_16_1(ftmp, sub( MAX_16 , alpha )), l_shift_val)); + move32(); + } + + /* update msNoiseEst in SID and NO_DATA frames */ + bandcombinepow( &st->hFdCngDec->smoothed_psd_fx[hFdCngCom->startBand], st->hFdCngDec->q_smoothed_psd, hFdCngCom->stopFFTbin - hFdCngCom->startBand, st->hFdCngDec->part_shaping, st->hFdCngDec->nFFTpart_shaping, st->hFdCngDec->psize_inv_shaping, st->hFdCngDec->msNoiseEst, &st->hFdCngDec->msNoiseEst_exp); + + st->hFdCngDec->first_cna_noise_updated = 1; move16(); + Copy32( st->hFdCngDec->msNoiseEst, st->hFdCngDec->msPeriodog_ST_fx, st->hFdCngDec->nFFTpart_shaping ); + st->hFdCngDec->ms_last_inactive_bwidth = st->bwidth; move16(); + } + + pop_wmops(); + return; +} +#endif + /*------------------------------------------------------------------- * stereo_dtf_cng() * @@ -694,6 +1412,51 @@ void stereo_dtf_cng( return; } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------- + * stereo_dtf_cng() + * + * DFT stereo CNG + *-------------------------------------------------------------------*/ + +void stereo_dtf_cng_fx( + CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word32 DFT[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* i/o: DFT buffers */ + const Word16 output_frame, /* i : output frame size */ + Word16 q_dft /* i : Q factor of the DFT data */ +) +{ + Decoder_State **sts; + Word16 n; + + sts = hCPE->hCoreCoder; + + IF ( hCPE->hStereoCng != NULL ) + { + IF ( hCPE->hStereoCng->nr_dft_frames < CM_INIT ) + { + hCPE->hStereoCng->nr_dft_frames++; + } + + IF ( LE_32(ivas_total_brate , IVAS_SID_5k2) ) + { + IF ( LT_16(hCPE->hStereoCng->nr_sid_frames , SID_INIT) && EQ_32(ivas_total_brate , IVAS_SID_5k2) ) + { + hCPE->hStereoCng->nr_sid_frames++; + } + + FOR ( n = 0; n < CPE_CHANNELS; n++ ) + { + stereo_dft_generate_comfort_noise_fx( hCPE->hStereoDft, hCPE->hStereoCng, hCPE->last_element_mode, sts[0], DFT, sts[1], extract_h(hCPE->hStereoTCA->targetGain_fx), n, output_frame, q_dft); + } + } + } + + return; +} +#endif + /*------------------------------------------------------------------- * stereo_cng_dec_update() diff --git a/lib_dec/ivas_stereo_dft_dec_dmx.c b/lib_dec/ivas_stereo_dft_dec_dmx.c index 9ac04152fc661c46d6f1681019491346635572f5..1e14973ea9ec4cbf04f2ed31f89c910ccc64bd6b 100644 --- a/lib_dec/ivas_stereo_dft_dec_dmx.c +++ b/lib_dec/ivas_stereo_dft_dec_dmx.c @@ -383,7 +383,7 @@ void add_HB_to_mono_dmx_fx( Word32 winSlope_fx = 0; Word32 alpha_fx; - const Word32 *win_dft_fx; + const Word16 *win_dft_fx; int32_t output_Fs; Word32 *memOutHB_fx, *memTransitionHB_fx; @@ -443,20 +443,20 @@ void add_HB_to_mono_dmx_fx( Copy32(outputHB + output_frame - memOffset, memOutHB_fx, memOffset); - win_dft_fx = (Word32 *)hCPE->hStereoDft->win32ms_fx; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Preparing buffers in anticipation of an ACELP to TCX switch */ j = 0; FOR (i = 0; i < memOffset; i++) { - memTransitionHB_fx[i] = memOutHB_fx[i] * win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]; + memTransitionHB_fx[i] = Mpy_32_16_1(memOutHB_fx[i], win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]); j++; } FOR (i = 0; j < dftOvlLen; i++) { - memTransitionHB_fx[memOffset + i] = outputHB[output_frame - i - 1] * win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]; + memTransitionHB_fx[memOffset + i] = Mpy_32_16_1(outputHB[output_frame - i - 1], win_dft_fx[STEREO_DFT32MS_STEP * (dftOvlLen - 1 - j)]); j++; } } diff --git a/lib_dec/ivas_stereo_dft_dec_fx.c b/lib_dec/ivas_stereo_dft_dec_fx.c index e2eb413819f4e99cd6ff41edf6bf8b96c7f0b2d1..3339fc218ff2ec0a75d7f269153b9cb49e240c6e 100644 --- a/lib_dec/ivas_stereo_dft_dec_fx.c +++ b/lib_dec/ivas_stereo_dft_dec_fx.c @@ -1265,7 +1265,7 @@ void stereo_dft_dec_res_fx( Copy( win, out_16, L_FRAME8k ); - IF ( hCPE->hCoreCoder[0]->core == ACELP_CORE ) + IF ( EQ_16(hCPE->hCoreCoder[0]->core , ACELP_CORE) ) { /* bass post-filter */ bass_psfilter_fx( hCPE->hStereoDft->hBpf, hCPE->hCoreCoder[0]->Opt_AMR_WB, out_16, L_FRAME8k, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx + ( L_FRAME8k / STEREO_DFT_L_SUBFR_8k ), hCPE->hCoreCoder[0]->bpf_off, diff --git a/lib_dec/ivas_stereo_icbwe_dec.c b/lib_dec/ivas_stereo_icbwe_dec.c index c2e2f43930fb79bc12474389cc3f6b18222748b3..c310ec894e9a7eea77fffc5ce79b7b152c814588 100644 --- a/lib_dec/ivas_stereo_icbwe_dec.c +++ b/lib_dec/ivas_stereo_icbwe_dec.c @@ -1590,7 +1590,9 @@ void stereo_icBWE_decproc( hCPE->hCoreCoder[0]->output_Fs); #endif +#ifndef IVAS_FLOAT_FIXED fd_bwe_dec_init_flt( hCPE->hCoreCoder[0]->hBWE_FD ); +#endif #ifdef IVAS_FLOAT_FIXED fd_bwe_dec_init(hCPE->hCoreCoder[0], hCPE->hCoreCoder[0]->hBWE_FD); #endif @@ -1628,18 +1630,19 @@ void stereo_icBWE_decproc_fx( CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ Word32 *output[CPE_CHANNELS], /* i/o: output synthesis */ Word32 outputHB[CPE_CHANNELS][L_FRAME48k], /* i : HB synthesis */ - const int16_t last_core, /* i : last core, primary channel */ - const int16_t last_bwidth, /* i : last bandwidth */ - const int16_t output_frame /* i : frame length */ + const Word16 last_core, /* i : last core, primary channel */ + const Word16 last_bwidth, /* i : last bandwidth */ + const Word16 output_frame, /* i : frame length */ + Word16 q_output /* i : Q-fac of output */ ) { - int16_t i, j, n, decoderDelay, icbweOLASize, dftOvlLen; - int16_t core, memOffset, refChanIndx_bwe; + Word16 i, j, n, decoderDelay, icbweOLASize, dftOvlLen; + Word16 core, memOffset, refChanIndx_bwe; Word32 temp0_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )], temp1_fx[L_FRAME48k + NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS )]; Word32 winSlope_fx = 0, alpha_fx; - const Word32 *win_dft_fx; - int32_t extl_brate, output_Fs; + const Word16 *win_dft_fx; + Word32 extl_brate, output_Fs; STEREO_ICBWE_DEC_HANDLE hStereoICBWE = hCPE->hStereoICBWE; @@ -1868,24 +1871,24 @@ void stereo_icBWE_decproc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { /*win_dft = hCPE->hStereoDft->win32ms;*/ - win_dft_fx = (Word32 *) hCPE->hStereoDft->win32ms_fx; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; /* Preparing buffers in anticipation of an ACELP to TCX switch */ j = 0; FOR( i = 0; i < memOffset; i++ ) { - Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( dftOvlLen - 1 - j ) ); - hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_32( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); - hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_32( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); + Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) ); + hStereoICBWE->memTransitionHB_fx[0][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[0][i], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[1][i] = Mpy_32_16_1( hStereoICBWE->memOutHB_fx[1][i], win_dft_fx[tmp_mul] ); j++; } FOR( i = 0; j < dftOvlLen; i++ ) { - Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( dftOvlLen - 1 - j ) ); - hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_32( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); - hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_32( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); + Word16 tmp_mul = mult0( STEREO_DFT32MS_STEP, ( sub( dftOvlLen, add( 1, j ) ) ) ); + hStereoICBWE->memTransitionHB_fx[0][memOffset + i] = Mpy_32_16_1( outputHB[0][output_frame - i - 1], win_dft_fx[tmp_mul] ); + hStereoICBWE->memTransitionHB_fx[1][memOffset + i] = Mpy_32_16_1( outputHB[1][output_frame - i - 1], win_dft_fx[tmp_mul] ); j++; } } @@ -1947,22 +1950,28 @@ void stereo_icBWE_decproc_fx( IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && ( max( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->td_gain_fx[1] ) > 0 ) ) { - Word32 win_in_fx, win_out_fx, tmp_fx; + Word32 win_in_fx, win_out_fx, tmp_fx, gain0_fx, gain1_fx; - win_dft_fx = (Word32 *) hCPE->hStereoDft->win32ms_fx; + win_dft_fx = hCPE->hStereoDft->win32ms_fx; dftOvlLen = hCPE->hStereoDft->dft32ms_ovl; FOR( i = 0; i < dftOvlLen; i++ ) { - win_in_fx = Mpy_32_32( win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )], win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )] ); - win_out_fx = L_sub( 1, win_in_fx ); - tmp_fx = Mpy_32_32( L_add( Mpy_32_32( win_in_fx, hCPE->hStereoDft->td_gain_fx[0] ), Mpy_32_32( win_out_fx, hCPE->hStereoDft->td_gain_fx[1] ) ), hCPE->hStereoDft->hb_stefi_sig_fx[i] ); - output[0][i] = L_add( output[0][i], tmp_fx ); - output[1][i] = L_sub( output[1][i], tmp_fx ); + win_in_fx = L_mult( win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )], win_dft_fx[mult0( STEREO_DFT32MS_STEP, i )] ); /* Q31 */ + win_out_fx = L_sub( ONE_IN_Q31, win_in_fx ); /* Q31 */ + + gain0_fx = Mpy_32_32( win_in_fx, hCPE->hStereoDft->td_gain_fx[0] ); /* Q --> q_td_gain[0] */ + gain0_fx = (Word32) W_shr( ( (Word64) gain0_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16)hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ) , q_output ) ); /* Q --> q_output */ + gain1_fx = Mpy_32_32( win_out_fx, hCPE->hStereoDft->td_gain_fx[1] ); /* Q --> q_td_gain[1] */ + gain1_fx = (Word32) W_shr( ( (Word64) gain1_fx * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16)hCPE->hStereoDft->q_td_gain[1], hCPE->hStereoDft->q_hb_stefi_sig_fx ) , q_output ) ); /* Q --> q_output */ + tmp_fx = L_add_sat( gain0_fx, gain1_fx ); /* Q --> q_output */ + + output[0][i] = L_add_sat( output[0][i], tmp_fx ); + output[1][i] = L_sub_sat( output[1][i], tmp_fx ); } FOR( i = dftOvlLen; i < output_frame; i++ ) - { - tmp_fx = Mpy_32_32( hCPE->hStereoDft->td_gain_fx[0], hCPE->hStereoDft->hb_stefi_sig_fx[i] ); + { + tmp_fx = (Word32) W_shr( ( (Word64) hCPE->hStereoDft->td_gain_fx[0] * hCPE->hStereoDft->hb_stefi_sig_fx[i] ), sub( add( (Word16)hCPE->hStereoDft->q_td_gain[0], hCPE->hStereoDft->q_hb_stefi_sig_fx ) , q_output ) ); /* Q --> q_output */ output[0][i] = L_add_sat( output[0][i], tmp_fx ); output[1][i] = L_sub_sat( output[1][i], tmp_fx ); } diff --git a/lib_dec/ivas_stereo_mdct_core_dec.c b/lib_dec/ivas_stereo_mdct_core_dec.c index ef6046c6f0eba1bb68c55a88e65098c701344e80..d5ff2caf440036ba9357970a57c6b7f964ccb635 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec.c +++ b/lib_dec/ivas_stereo_mdct_core_dec.c @@ -485,7 +485,7 @@ void stereo_mdct_core_dec( pop_wmops(); return; } -#endif + /*-------------------------------------------------------------------* * apply_dmx_weights() @@ -771,3 +771,5 @@ static void run_min_stats( return; } +#endif + diff --git a/lib_dec/ivas_stereo_mdct_core_dec_fx.c b/lib_dec/ivas_stereo_mdct_core_dec_fx.c index c573e023b0453842d3302d7f6af3b16d619abfaf..2fe2fd4fe65e6e733a67f332319ad52539f10c38 100644 --- a/lib_dec/ivas_stereo_mdct_core_dec_fx.c +++ b/lib_dec/ivas_stereo_mdct_core_dec_fx.c @@ -52,7 +52,7 @@ static void apply_dmx_weights_fx( CPE_DEC_HANDLE hCPE, Word32 *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); static void apply_dmx_weights( CPE_DEC_HANDLE hCPE, float *x[CPE_CHANNELS][NB_DIV], int16_t transform_type_left[NB_DIV], int16_t transform_type_right[NB_DIV] ); -static void run_min_stats_fx( Decoder_State **sts, float *x[CPE_CHANNELS][NB_DIV] ); +static void run_min_stats_fx( Decoder_State **sts, Word32 *x[CPE_CHANNELS][NB_DIV], Word16 x_e[MAX_CICP_CHANNELS][NB_DIV]); /*-------------------------------------------------------------------* * stereo_mdct_dec_stereo() @@ -263,7 +263,7 @@ void stereo_mdct_core_dec_fx( sts[ch]->Mode2_lp_gainp = float_to_fix( sts[ch]->lp_gainp, Q16 ); sts[ch]->hTcxLtpDec->tcxltp_gain = float_to_fix16( sts[ch]->hTcxLtpDec->tcxltp_gain_float, Q15 ); //sts[ch]->inv_gamma = float_to_fix16( 1 / sts[ch]->gamma_float, Q14 ); - f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); + //f2me_16( sts[ch]->last_gain_syn_deemph_float, &sts[ch]->last_gain_syn_deemph, &sts[ch]->last_gain_syn_deemph_e ); f2me_16( sts[ch]->last_concealed_gain_syn_deemph_float, &sts[ch]->last_concealed_gain_syn_deemph, &sts[ch]->last_concealed_gain_syn_deemph_e ); f2me_16( sts[ch]->hTcxDec->old_gaintcx_bfi_float, &sts[ch]->hTcxDec->old_gaintcx_bfi, &sts[ch]->hTcxDec->old_gaintcx_bfi_e ); floatToFixed_arr( Aq[ch], Aq_fx[ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); @@ -316,7 +316,7 @@ void stereo_mdct_core_dec_fx( sts[ch]->hTcxDec->stepCompensate_float = me2f_16( sts[ch]->hTcxDec->stepCompensate, sts[ch]->hTcxDec->stepCompensate_e ); sts[ch]->hTcxDec->gainHelper_float = me2f_16( sts[ch]->hTcxDec->gainHelper, sts[ch]->hTcxDec->gainHelper_e ); sts[ch]->last_concealed_gain_syn_deemph_float = me2f_16( sts[ch]->last_concealed_gain_syn_deemph, sts[ch]->last_concealed_gain_syn_deemph_e ); - sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); + //sts[ch]->last_gain_syn_deemph_float = me2f_16( sts[ch]->last_gain_syn_deemph, sts[ch]->last_gain_syn_deemph_e ); sts[ch]->hTcxDec->old_gaintcx_bfi_float = me2f_16( sts[ch]->hTcxDec->old_gaintcx_bfi, sts[ch]->hTcxDec->old_gaintcx_bfi_e ); fixedToFloat_arr( Aq_fx[ch], Aq[ch], Q12, ( NB_SUBFR16k + 1 ) * ( M + 1 ) ); // 16bit to u8bit @@ -553,13 +553,13 @@ void stereo_mdct_core_dec_fx( float sns_int_scf[FDNS_NPTS]; #ifdef IVAS_FLOAT_FIXED - Word32 sns_int_scf_fx[FDNS_NPTS], Aq_fx[(NB_SUBFR16k + 1) * (M + 1)]; + Word32 sns_int_scf_fx[FDNS_NPTS], Aq_fx[CPE_CHANNELS][(NB_SUBFR16k + 1) * (M + 1)]; FOR(int c = 0; c < (NB_SUBFR16k + 1) * (M + 1); c++) { - Aq_fx[c] = (Word32) ( Aq[ch][k * M + c] * ONE_IN_Q16 ); + Aq_fx[ch][c] = (Word32) ( Aq[ch][c] * ONE_IN_Q16 ); } - sns_interpolate_scalefactors_fx( sns_int_scf_fx, Aq_fx, DEC ); + sns_interpolate_scalefactors_fx( sns_int_scf_fx, &Aq_fx[ch][k * M], DEC ); FOR( int c = 0; c < FDNS_NPTS; c++ ) { @@ -740,17 +740,182 @@ void stereo_mdct_core_dec_fx( ivas_ls_setup_conversion_process_mdct_param_mc( st_ivas, x ); #endif // IVAS_FLOAT_FIXED } - FOR( Word16 i = 0; i < CPE_CHANNELS; i++ ) + +#ifdef IVAS_FLOAT_FIXED + int16_t will_estimate_noise_on_channel[CPE_CHANNELS]; + + will_estimate_noise_on_channel[0] = sts[0]->core == TCX_20_CORE && !sts[0]->VAD; + will_estimate_noise_on_channel[1] = sts[1]->core == TCX_20_CORE && !sts[1]->VAD; + for (int n = 0; n < CPE_CHANNELS; n++) + { + + if (!sts[0]->bfi && (will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1])) + { + sts[n]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = floatToFixed(sts[n]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 31); + sts[n]->lp_noise = floatToFixed(sts[n]->lp_noise_float, 23); + sts[n]->hFdCngDec->lp_noise = floatToFixed(sts[n]->hFdCngDec->lp_noise_float, 23); + sts[n]->hFdCngDec->lp_speech = floatToFixed(sts[n]->hFdCngDec->lp_speech_float, 23); + } + IF(will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || sts[n]->bfi) + { + for (int p = 0; p < sts[n]->hFdCngDec->hFdCngCom->fftlen; p++) { - FOR( Word16 j = 0; j < NB_DIV; j++ ) - { - free( x_fx[i][j] ); - } + sts[n]->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32)(sts[n]->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * (1u << (31 - sts[n]->hFdCngDec->hFdCngCom->fftBuffer_exp))); } + sts[n]->hFdCngDec->msNoiseEst_exp = 31 - Q4; + for (int p = 0; p < NPART_SHAPING; p++) + { + sts[n]->hFdCngDec->msNoiseEst[p] = (Word32)(sts[n]->hFdCngDec->msNoiseEst_float[p] * (1u << (31 - sts[n]->hFdCngDec->msNoiseEst_exp))); + sts[n]->hFdCngDec->msPeriodog_ST_fx[p] = (Word32)(sts[n]->hFdCngDec->msPeriodog_ST[p] * (1u << (31 - sts[n]->hFdCngDec->msPeriodog_ST_exp))); + } + sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q3; // Q3 + for (int p = 0; p < FFTCLDFBLEN; p++) + { + sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32)(sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * (1u << (31 - sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); + } + for (int p = 0; p < MSBUFLEN * NPART_SHAPING; p++) + { + if ((sts[n]->hFdCngDec->msMinBuf_float[p] * (1u << Q15)) >= (float)MAX_32) + { + sts[n]->hFdCngDec->msMinBuf[p] = MAX_32; + } + else + { + sts[n]->hFdCngDec->msMinBuf[p] = (Word32)(sts[n]->hFdCngDec->msMinBuf_float[p] * (1u << (31 - 6))); + } + } + } } +#endif + + run_min_stats_fx( sts, x_fx, x_e); - run_min_stats_fx( sts, x ); +#ifdef IVAS_FLOAT_FIXED + if (!sts[0]->bfi && (will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1])) + { + FOR(Word16 ind = 0; ind < 2; ind++) + { + me2f_buf(x_fx[ind][0], x_e[ind][0], x[ind][0], 1200); + me2f_buf(x_fx[ind][1], x_e[ind][1], x[ind][1], 600); + } + } + FOR(Word16 i = 0; i < CPE_CHANNELS; i++) + { + FOR(Word16 j = 0; j < NB_DIV; j++) + { + free(x_fx[i][j]); + } + } + for (int n = 0; n < CPE_CHANNELS; n++) + { + if (!sts[0]->bfi && (will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1])) + { + sts[n]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = fixedToFloat(sts[n]->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx, 31); + sts[n]->lp_noise_float = fixedToFloat(sts[n]->lp_noise, 23); + sts[n]->hFdCngDec->lp_noise_float = fixedToFloat(sts[n]->hFdCngDec->lp_noise, 23); + sts[n]->hFdCngDec->lp_speech_float = fixedToFloat(sts[n]->hFdCngDec->lp_speech, 23); + } + + IF(will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || sts[n]->bfi) + { + if (!sts[n]->bfi) + { + for (int p = 0; p < sts[n]->hFdCngDec->hFdCngCom->fftlen; p++) + { + sts[n]->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ((float)sts[n]->hFdCngDec->hFdCngCom->fftBuffer[p] / (1u << (31 - sts[n]->hFdCngDec->hFdCngCom->fftBuffer_exp))); + } + for (int p = 0; p < sts[n]->hFdCngDec->npart_shaping; p++) + { + sts[n]->hFdCngDec->msNoiseEst_float[p] = ((float)sts[n]->hFdCngDec->msNoiseEst[p] / (1u << (31 - sts[n]->hFdCngDec->msNoiseEst_exp))); + } + + sts[n]->hTcxDec->CngLevelBackgroundTrace_bfi = (float)(sts[n]->hTcxDec->CngLevelBackgroundTrace_bfi_fx / powf(2.f, (Float32)(31 - sts[n]->hTcxDec->CngLevelBackgroundTrace_bfi_exp))); + sts[n]->cngTDLevel_float = fixedToFloat(sts[n]->cngTDLevel, (15 - sts[n]->cngTDLevel_e)); + + for (int p = 0; p < (sts[n]->hFdCngDec->hFdCngCom->stopFFTbin - sts[n]->hFdCngDec->hFdCngCom->startBand); p++) + { + sts[n]->hFdCngDec->bandNoiseShape_float[p] = ((float)sts[n]->hFdCngDec->bandNoiseShape[p] / (1u << (31 - sts[n]->hFdCngDec->bandNoiseShape_exp))); + } + for (int p = 0; p < MSBUFLEN * NPART_SHAPING; p++) + { + if ((sts[n]->hFdCngDec->msMinBuf[p] == MAX_32)) + { + sts[n]->hFdCngDec->msMinBuf_float[p] = FLT_MAX; + } + else + { + sts[n]->hFdCngDec->msMinBuf_float[p] = (float)sts[n]->hFdCngDec->msMinBuf[p] / (1u << (31 - 6)); // CNG_S = 6 + } + } + for (int p = 0; p < sts[n]->hFdCngDec->npart_shaping; p++) + { + sts[n]->hFdCngDec->msPsd_float[p] = ((float)sts[n]->hFdCngDec->msPsd[p] / (1u << Q9)); + sts[n]->hFdCngDec->msPeriodog_float[p] = ((float)sts[n]->hFdCngDec->msPeriodog[p] / (1u << (31 - sts[n]->hFdCngDec->msPeriodog_exp))); + sts[n]->hFdCngDec->msPeriodogBuf_float[p] = ((float)sts[n]->hFdCngDec->msPeriodogBuf[p] / (1u << Q9)); + sts[n]->hFdCngDec->msPeriodog_ST[p] = ((float)sts[n]->hFdCngDec->msPeriodog_ST_fx[p] / (1u << (31 - sts[n]->hFdCngDec->msPeriodog_ST_exp))); + sts[n]->hFdCngDec->msPsdFirstMoment_float[p] = ((float)sts[n]->hFdCngDec->msPsdFirstMoment[p] / (1u << Q9)); + sts[n]->hFdCngDec->msPsdSecondMoment_float[p] = ((float)sts[n]->hFdCngDec->msPsdSecondMoment[p] / (1u << Q19)); + sts[n]->hFdCngDec->msNoiseFloor_float[p] = ((float)sts[n]->hFdCngDec->msNoiseFloor[p] / (1u << Q9)); + sts[n]->hFdCngDec->msAlpha_float[p] = ((float)sts[n]->hFdCngDec->msAlpha[p] / (1u << Q31)); + sts[n]->hFdCngDec->msBminWin_float[p] = ((float)sts[n]->hFdCngDec->msBminWin[p] / (1u << Q27)); + sts[n]->hFdCngDec->msBminSubWin_float[p] = ((float)sts[n]->hFdCngDec->msBminSubWin[p] / (1u << Q27)); + if (sts[n]->hFdCngDec->msCurrentMin[p] == MAX_32) + { + sts[n]->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; + } + else + { + sts[n]->hFdCngDec->msCurrentMin_float[p] = ((float)sts[n]->hFdCngDec->msCurrentMin[p] / (1u << (31 - (6 + 1 + 4)))); // exp : CNG_S + 1 + 4 + } + if (sts[n]->hFdCngDec->msCurrentMinOut[p] == MAX_32) + { + sts[n]->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; + } + else + { + sts[n]->hFdCngDec->msCurrentMinOut_float[p] = ((float)sts[n]->hFdCngDec->msCurrentMinOut[p] / (1u << (31 - 6))); + } + if (sts[n]->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32) + { + sts[n]->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; + } + else + { + sts[n]->hFdCngDec->msCurrentMinSubWindow_float[p] = ((float)sts[n]->hFdCngDec->msCurrentMinSubWindow[p] / (1u << (31 - 6))); + } + } + for (int p = 0; p < (sts[n]->hFdCngDec->hFdCngCom->stopFFTbin - sts[n]->hFdCngDec->hFdCngCom->startBand); p++) + { + sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ((float)sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / (1u << (31 - sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); + } + } + else if (((sts[n]->bfi == 1) && (sts[n]->nbLostCmpt == 1)) && (sum_f(sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + sts[n]->hFdCngDec->hFdCngCom->startBand, sts[n]->hFdCngDec->hFdCngCom->stopFFTbin - sts[n]->hFdCngDec->hFdCngCom->startBand) > 0.01f)) + { + if (sts[n]->element_mode == IVAS_CPE_MDCT && sts[n]->core != ACELP_CORE) + { + for (int p = 0; p < (sts[n]->hFdCngDec->hFdCngCom->stopFFTbin - sts[n]->hFdCngDec->hFdCngCom->startBand); p++) + { + sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ((float)sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / (1u << (31 - sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp))); + } + for (int p = 0; p < FDNS_NPTS; p++) + { + sts[n]->hTonalMDCTConc->scaleFactorsBackground_flt[p] = (float)sts[n]->hTonalMDCTConc->scaleFactorsBackground_fx[p] / ONE_IN_Q16; + } + } + if (sts[n]->element_mode != IVAS_CPE_MDCT || sts[n]->core == ACELP_CORE) + { + int A_cng_q = 15 - norm_s(sts[n]->hFdCngDec->hFdCngCom->A_cng[0]); + for (int p = 0; p < M; p++) + { + sts[n]->hFdCngDec->hFdCngCom->A_cng_flt[p] = ((float)sts[n]->hFdCngDec->hFdCngCom->A_cng[p] / (1u << A_cng_q)); + } + } + } + } + } +#endif +} if ( hCPE->nchan_out == 1 && ( !bfi || ( bfi && sts[0]->core != ACELP_CORE && sts[1]->core != ACELP_CORE ) ) ) { #ifdef IVAS_FLOAT_FIXED @@ -838,6 +1003,7 @@ void stereo_mdct_core_dec_fx( IF(st->hTonalMDCTConc) st->hTonalMDCTConc->lastPitchLag = float_to_fix(st->hTonalMDCTConc->lastPitchLag_float, Q16); st->enr_old_fx = (Word32)st->enr_old; + st->stab_fac_fx = float_to_fix16(st->stab_fac, Q15); IF(st->hHQ_core) floatToFixed_arr(st->hHQ_core->old_outLB, st->hHQ_core->old_out_LB_fx, st->Q_syn, L_FRAME32k); IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->syn_Overl_TDACFB_float, st->hTcxDec->syn_Overl_TDACFB, -1 - st->Q_syn, L_FRAME_MAX / 2); @@ -845,7 +1011,7 @@ void stereo_mdct_core_dec_fx( IF(st->hTcxDec) floatToFixed_arr(st->hTcxDec->old_syn_Overl_float, st->hTcxDec->old_syn_Overl, -1 - st->Q_syn, L_FRAME32k / 2); //floatToFixed_arr( st->mem_syn2, st->mem_syn2_fx, st->Q_syn, M ); //floatToFixed_arr( st->mem_syn_r_float, st->mem_syn_r, st->Q_syn, L_SYN_MEM ); - floatToFixed_arr( st->syn_float, st->syn, -1, M + 1 ); + floatToFixed_arr( st->syn_float, st->syn, st->Q_syn, M + 1 ); //floatToFixed_arr( st->old_exc, st->old_exc_fx, st->Q_exc, L_EXC_MEM_DEC ); IF(st->hTcxDec) st->hTcxDec->tcxltp_third_last_pitch = float_to_fix(st->hTcxDec->tcxltp_third_last_pitch_float, 16); @@ -889,8 +1055,8 @@ void stereo_mdct_core_dec_fx( st->hFdCngDec->hFdCngCom->likelihood_noisy_speech = float_to_fix16(st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt, 15); } IF(st->hHQ_core) floatToFixed_arr(st->hHQ_core->old_out, st->hHQ_core->old_out_fx, st->Q_syn, 960); - IF(st->hTonalMDCTConc) floatToFixed_arr(st->hTonalMDCTConc->lastPcmOut_float, st->hTonalMDCTConc->lastPcmOut, -2, st->hTonalMDCTConc->nSamples); - IF(st->hTonalMDCTConc) floatToFixed_arr(st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, -2, st->hTonalMDCTConc->nSamples / 2); + IF(st->hTonalMDCTConc) floatToFixed_arr(st->hTonalMDCTConc->lastPcmOut_float, st->hTonalMDCTConc->lastPcmOut, 0, st->hTonalMDCTConc->nSamples); + IF(st->hTonalMDCTConc) floatToFixed_arr(st->hTonalMDCTConc->secondLastPcmOut_float, st->hTonalMDCTConc->secondLastPcmOut, 0, st->hTonalMDCTConc->nSamples / 2); if ( st->hPlcInfo ) { //st->hPlcInfo->step_concealgain_fx = float_to_fix16( st->hPlcInfo->step_concealgain, Q15 ); @@ -898,10 +1064,8 @@ void stereo_mdct_core_dec_fx( } IF(st->hTcxDec) st->hTcxDec->conceal_eof_gain = float_to_fix16( st->hTcxDec->conceal_eof_gain_float, Q14 ); - if ( st->hTcxDec && st->hTcxDec->conCngLevelBackgroundTrace_e < 0 ) - { - st->hTcxDec->conCngLevelBackgroundTrace_e = 0; - } + /*IF(st->hTcxDec) st->hTcxDec->conCngLevelBackgroundTrace = (Word16)floatToFixed(st->hTcxDec->CngLevelBackgroundTrace_bfi, 15); + st->hTcxDec->conCngLevelBackgroundTrace_e = 0;*/ IF(st->hTcxDec) f2me_16(st->hTcxDec->CngLevelBackgroundTrace_bfi, &st->hTcxDec->conCngLevelBackgroundTrace, &st->hTcxDec->conCngLevelBackgroundTrace_e); if ( st->hTcxDec && st->hTcxDec->conLastFrameLevel_e < 0 ) { @@ -912,7 +1076,11 @@ void stereo_mdct_core_dec_fx( { set16_fx( st->hTcxDec->conNoiseLevelMemory_e, 0, PLC_MIN_STAT_BUFF_SIZE ); } - IF(st->hTcxDec) floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); + for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) + { + //f2me_16( st->hTcxDec->NoiseLevelMemory_bfi[p], &st->hTcxDec->conNoiseLevelMemory[p], &st->hTcxDec->conNoiseLevelMemory_e[p] ); + } + //IF(st->hTcxDec) floatToFixed_arr( st->hTcxDec->NoiseLevelMemory_bfi, st->hTcxDec->conNoiseLevelMemory, Q15, PLC_MIN_STAT_BUFF_SIZE ); IF(st->hTcxDec) st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; IF(st->hTcxDec) st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; floatToFixed_arrL( st->old_pitch_buf, st->old_pitch_buf_fx, Q16, 2 * NB_SUBFR16k + 2 ); @@ -1007,10 +1175,10 @@ void stereo_mdct_core_dec_fx( st->hTcxDec->LastFrameLevel_bfi = me2f_16( st->hTcxDec->conLastFrameLevel, st->hTcxDec->conLastFrameLevel_e ); for ( int p = 0; p < PLC_MIN_STAT_BUFF_SIZE; p++ ) { - st->hTcxDec->NoiseLevelMemory_bfi[p] = me2f_16( st->hTcxDec->conNoiseLevelMemory[p], 0 ); + //st->hTcxDec->NoiseLevelMemory_bfi[p] = me2f_16( st->hTcxDec->conNoiseLevelMemory[p], st->hTcxDec->conNoiseLevelMemory_e[p] ); } - IF(st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float) fixedToFloat_arr(st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, -2, st->hTonalMDCTConc->nSamples); - IF( bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) fixedToFloat_arr(st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, -2, st->hTonalMDCTConc->nSamples / 2); + IF(st->hTonalMDCTConc && st->hTonalMDCTConc->lastPcmOut_float) fixedToFloat_arr(st->hTonalMDCTConc->lastPcmOut, st->hTonalMDCTConc->lastPcmOut_float, 0, st->hTonalMDCTConc->nSamples); + IF( bfi == 0 && !st->hTonalMDCTConc->secondLastBlockData.tonalConcealmentActive ) fixedToFloat_arr(st->hTonalMDCTConc->secondLastPcmOut, st->hTonalMDCTConc->secondLastPcmOut_float, 0, st->hTonalMDCTConc->nSamples / 2); } FOR( i = 0; i < 2; i++ ) { @@ -1509,13 +1677,15 @@ static void apply_dmx_weights_fx( static void run_min_stats_fx( Decoder_State **sts, - float *x[CPE_CHANNELS][NB_DIV] /* i/o: MDCT Spectrum */ + Word32 *x[CPE_CHANNELS][NB_DIV], /* i/o: MDCT Spectrum */ + Word16 x_e[MAX_CICP_CHANNELS][NB_DIV] ) { int16_t ch, will_estimate_noise_on_channel[CPE_CHANNELS], save_VAD[CPE_CHANNELS]; - float power_spec[L_FRAME16k]; - float *spec_in; - + Word32 power_spec[L_FRAME16k]; + Word16 power_spec_16[L_FRAME16k], power_spec_16e = 0, power_spec_e = 0; + Word32 *spec_in; + Word16 spec_e; /* Check if the minimum statistics would run on the respective channels. They are run on inactive TCX20 channels */ will_estimate_noise_on_channel[0] = sts[0]->core == TCX_20_CORE && !sts[0]->VAD; will_estimate_noise_on_channel[1] = sts[1]->core == TCX_20_CORE && !sts[1]->VAD; @@ -1528,195 +1698,58 @@ static void run_min_stats_fx( for the two different channels. If they would only run on one of the channels, the VAD of the other one is patched so that the MS will still run. This other channel then uses the power spectrum of the other channel to run the MS. This is done to keep continuity and synchronicity between the two noise levels and silently assumes that the background noise is somehow diffuse and at leas partly shared between the channels */ - for ( ch = 0; ch < CPE_CHANNELS; ch++ ) + FOR ( ch = 0; ch < CPE_CHANNELS; ch++ ) { Decoder_State *st; st = sts[ch]; - if ( !sts[0]->bfi && ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] ) ) + IF ( !sts[0]->bfi && ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] ) ) { /* if noise estimation is expected to run on this channel, compute power spectrum from it, otherwise, use other channel's signal */ - if ( will_estimate_noise_on_channel[ch] ) + IF ( will_estimate_noise_on_channel[ch] ) { spec_in = &x[ch][0][0]; + spec_e = x_e[ch][0]; } - else + ELSE { spec_in = &x[( ch + 1 ) % 2][0][0]; + spec_e = x_e[(ch + 1) % 2][0]; /* patch VAD to zero so that estimation runs, will later be restored */ st->VAD = 0; } /* Compute power spectrum twice if estimation will run on both channels. If only on one channel, it is computed only once (for ch == 0) and not again in the second run sive the outcome will be the same anyway */ - if ( ( will_estimate_noise_on_channel[0] == will_estimate_noise_on_channel[1] ) || ch == 0 ) + IF ( ( EQ_16(will_estimate_noise_on_channel[0], will_estimate_noise_on_channel[1]) ) || EQ_16(ch, 0) ) { /* calculate power spectrum from MDCT coefficients and estimated MDST coeffs */ - power_spec[0] = spec_in[0] * spec_in[0]; - power_spec[L_FRAME16k - 1] = spec_in[L_FRAME16k - 1] * spec_in[L_FRAME16k - 1]; - for ( int16_t i = 1; i < L_FRAME16k - 1; i++ ) + power_spec[0] = Mpy_32_32(L_shr(spec_in[0], 2), L_shr(spec_in[0], 2)); + power_spec[L_FRAME16k - 1] = Mpy_32_32(L_shr(spec_in[L_FRAME16k - 1], 1), L_shr(spec_in[L_FRAME16k - 1], 1)); + FOR ( Word16 i = 1; i < L_FRAME16k - 1; i++ ) { - float mdst; - mdst = spec_in[i + 1] - spec_in[i - 1]; - power_spec[i] = spec_in[i] * spec_in[i] + mdst * mdst; + Word32 mdst; + mdst = L_sub(L_shr(spec_in[i + 1], 2), L_shr(spec_in[i - 1], 2)); + power_spec[i] = L_add(Mpy_32_32(L_shr(spec_in[i], 2), L_shr(spec_in[i], 2)), Mpy_32_32(L_shr(mdst, 0), L_shr(mdst, 0))); } } + power_spec_e = add(4, shl(spec_e, 1)); - noisy_speech_detection_flt( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec ); + Copy_Scale_sig32_16(power_spec, power_spec_16, L_FRAME16k, 0); + + noisy_speech_detection( st->hFdCngDec, st->VAD && st->m_frame_type == ACTIVE_FRAME, power_spec_16, sub(15, power_spec_e)); - st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt = 0.99f * st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_flt + 0.01f * (float) st->hFdCngDec->hFdCngCom->flag_noisy_speech; + st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx = L_add(Mpy_32_32(Q31_0_99, st->hFdCngDec->hFdCngCom->likelihood_noisy_speech_32fx), Mpy_32_32(st->hFdCngDec->hFdCngCom->flag_noisy_speech, Q31_0_01)); - st->lp_noise_float = st->hFdCngDec->lp_noise_float; + st->lp_noise = st->hFdCngDec->lp_noise; } - if ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || st->bfi ) + IF ( will_estimate_noise_on_channel[0] || will_estimate_noise_on_channel[1] || st->bfi ) { -#ifdef IVAS_FLOAT_FIXED - Word32 power_spec_fx[L_FRAME16k]; - - if ( !st->bfi ) - { - for ( int p = 0; p < L_FRAME16k; p++ ) - { - if ( power_spec[p] <= (float) MAX_32 ) - { - power_spec_fx[p] = (Word32) ( power_spec[p] /** ( 1u << 0 )*/ ); - } - else - { - power_spec_fx[p] = MAX_32; - } - } - } - - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer[p] = (Word32) ( st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - st->hFdCngDec->msNoiseEst_exp = 31 - Q4; - for ( int p = 0; p < NPART_SHAPING; p++ ) - { - st->hFdCngDec->msNoiseEst[p] = (Word32) ( st->hFdCngDec->msNoiseEst_float[p] * ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - st->hFdCngDec->msPeriodog_ST_fx[p] = (Word32) ( st->hFdCngDec->msPeriodog_ST[p] * ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - } - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 31 - Q3; // Q3 - for ( int p = 0; p < FFTCLDFBLEN; p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] = (Word32) ( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] * ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << Q15 ) ) >= (float) MAX_32 ) - { - st->hFdCngDec->msMinBuf[p] = MAX_32; - } - else - { - st->hFdCngDec->msMinBuf[p] = (Word32) ( st->hFdCngDec->msMinBuf_float[p] * ( 1u << ( 31 - 6 ) ) ); - } - } /*=================================================*/ - ApplyFdCng_fx( NULL, 0, st->bfi ? NULL : power_spec_fx, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( NULL, 0, st->bfi ? NULL : power_spec, sub(31, power_spec_e), NULL, NULL, NULL, st, st->bfi, 0 ); /*=================================================*/ - if ( !st->bfi ) - { - for ( int p = 0; p < st->hFdCngDec->hFdCngCom->fftlen; p++ ) - { - st->hFdCngDec->hFdCngCom->fftBuffer_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->fftBuffer[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->fftBuffer_exp ) ) ); - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msNoiseEst_float[p] = ( (float) st->hFdCngDec->msNoiseEst[p] / ( 1u << ( 31 - st->hFdCngDec->msNoiseEst_exp ) ) ); - } - - st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) ( st->hTcxDec->CngLevelBackgroundTrace_bfi_fx / powf( 2.f, (Float32)( 31 - st->hTcxDec->CngLevelBackgroundTrace_bfi_exp ) ) ); - st->cngTDLevel_float = fixedToFloat( st->cngTDLevel, ( 15 - st->cngTDLevel_e ) ); - - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->bandNoiseShape_float[p] = ( (float) st->hFdCngDec->bandNoiseShape[p] / ( 1u << ( 31 - st->hFdCngDec->bandNoiseShape_exp ) ) ); - } - for ( int p = 0; p < MSBUFLEN * NPART_SHAPING; p++ ) - { - if ( ( st->hFdCngDec->msMinBuf[p] == MAX_32 ) ) - { - st->hFdCngDec->msMinBuf_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msMinBuf_float[p] = (float) st->hFdCngDec->msMinBuf[p] / ( 1u << ( 31 - 6 ) ); // CNG_S = 6 - } - } - for ( int p = 0; p < st->hFdCngDec->npart_shaping; p++ ) - { - st->hFdCngDec->msPsd_float[p] = ( (float) st->hFdCngDec->msPsd[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPeriodog_float[p] = ( (float) st->hFdCngDec->msPeriodog[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_exp ) ) ); - st->hFdCngDec->msPeriodogBuf_float[p] = ( (float) st->hFdCngDec->msPeriodogBuf[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPeriodog_ST[p] = ( (float) st->hFdCngDec->msPeriodog_ST_fx[p] / ( 1u << ( 31 - st->hFdCngDec->msPeriodog_ST_exp ) ) ); - st->hFdCngDec->msPsdFirstMoment_float[p] = ( (float) st->hFdCngDec->msPsdFirstMoment[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msPsdSecondMoment_float[p] = ( (float) st->hFdCngDec->msPsdSecondMoment[p] / ( 1u << Q19 ) ); - st->hFdCngDec->msNoiseFloor_float[p] = ( (float) st->hFdCngDec->msNoiseFloor[p] / ( 1u << Q9 ) ); - st->hFdCngDec->msAlpha_float[p] = ( (float) st->hFdCngDec->msAlpha[p] / ( 1u << Q31 ) ); - st->hFdCngDec->msBminWin_float[p] = ( (float) st->hFdCngDec->msBminWin[p] / ( 1u << Q27 ) ); - st->hFdCngDec->msBminSubWin_float[p] = ( (float) st->hFdCngDec->msBminSubWin[p] / ( 1u << Q27 ) ); - if ( st->hFdCngDec->msCurrentMin[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMin_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMin_float[p] = ( (float) st->hFdCngDec->msCurrentMin[p] / ( 1u << ( 31 - ( 6 + 1 + 4 ) ) ) ); // exp : CNG_S + 1 + 4 - } - if ( st->hFdCngDec->msCurrentMinOut[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinOut_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinOut_float[p] = ( (float) st->hFdCngDec->msCurrentMinOut[p] / ( 1u << ( 31 - 6 ) ) ); - } - if ( st->hFdCngDec->msCurrentMinSubWindow[p] == MAX_32 ) - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = FLT_MAX; - } - else - { - st->hFdCngDec->msCurrentMinSubWindow_float[p] = ( (float) st->hFdCngDec->msCurrentMinSubWindow[p] / ( 1u << ( 31 - 6 ) ) ); - } - } - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - } - else if ( ( ( st->bfi == 1 ) && ( st->nbLostCmpt == 1 ) ) && ( sum_f( st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt + st->hFdCngDec->hFdCngCom->startBand, st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ) > 0.01f ) ) - { - if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE ) - { - for ( int p = 0; p < ( st->hFdCngDec->hFdCngCom->stopFFTbin - st->hFdCngDec->hFdCngCom->startBand ); p++ ) - { - st->hFdCngDec->hFdCngCom->cngNoiseLevel_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->cngNoiseLevel[p] / ( 1u << ( 31 - st->hFdCngDec->hFdCngCom->cngNoiseLevelExp ) ) ); - } - for ( int p = 0; p < FDNS_NPTS; p++ ) - { - st->hTonalMDCTConc->scaleFactorsBackground_flt[p] = (float) st->hTonalMDCTConc->scaleFactorsBackground_fx[p] / ONE_IN_Q16; - } - } - if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE ) - { - int A_cng_q = 15 - norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] ); - for ( int p = 0; p < M; p++ ) - { - st->hFdCngDec->hFdCngCom->A_cng_flt[p] = ( (float) st->hFdCngDec->hFdCngCom->A_cng[p] / ( 1u << A_cng_q ) ); - //st->lspold_cng_float[p] = ( (float) st->lspold_cng[p] / ( 1u << Q15 ) ); - //st->lsf_cng_float[p] = ( (float) st->lsf_cng[p] / 2.56f ); // Q2.56 - } - } - } -#else - ApplyFdCng_flt( NULL, st->bfi ? NULL : power_spec, NULL, NULL, st, st->bfi, 0 ); -#endif // IVAS_FLOAT_FIXED } /* restore VAD (see above) */ @@ -1725,4 +1758,4 @@ static void run_min_stats_fx( return; } -#endif // IVAS_FLOAT_FIXED +#endif diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index f588aa1c02b5b3c515bae1ed3505daf8065c3711..27614c43e544404d6c60ba06174b84c8fd2edd81 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -227,6 +227,7 @@ static ivas_error allocate_CoreCoder_TCX_fx( } #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function allocate_CoreCoder() * @@ -249,10 +250,6 @@ static ivas_error allocate_CoreCoder( } GSC_dec_init_ivas( st->hGSCDec ); -#ifdef IVAS_FLOAT_FIXED - GSC_dec_init_ivas( st->hGSCDec ); -#endif // IVAS_FLOAT_FIXED - } if ( st->hPFstat == NULL ) @@ -319,6 +316,7 @@ static ivas_error allocate_CoreCoder( return error; } +#endif #ifdef IVAS_FLOAT_FIXED static ivas_error allocate_CoreCoder_fx( @@ -336,11 +334,7 @@ static ivas_error allocate_CoreCoder_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for GSC\n" ) ); } - GSC_dec_init( st->hGSCDec ); - -#if 1 // TODO: To be removed later - GSC_dec_init_ivas( st->hGSCDec ); -#endif + GSC_dec_init_ivas_fx( st->hGSCDec ); } IF ( st->hPFstat == NULL ) @@ -396,10 +390,6 @@ static ivas_error allocate_CoreCoder_fx( } hf_synth_init_fx( st->hBWE_zero ); - -#if 1 // TODO: To be removed later - hf_synth_init( st->hBWE_zero ); -#endif } IF ( st->cldfbAna == NULL ) @@ -621,6 +611,7 @@ static void cpy_tcx_ltp_data_fx( #endif +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function stereo_memory_dec() * @@ -1376,6 +1367,7 @@ ivas_error stereo_memory_dec( return error; } +#endif #ifdef IVAS_FLOAT_FIXED ivas_error stereo_memory_dec_fx( @@ -1565,7 +1557,7 @@ ivas_error stereo_memory_dec_fx( stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); /* allocate CoreCoder secondary channel */ - IF ( NE_16(( error = allocate_CoreCoder( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK) ) + IF ( NE_16(( error = allocate_CoreCoder_fx( hCPE->hCoreCoder[1] ) ), IVAS_ERR_OK) ) { return error; } @@ -1667,9 +1659,9 @@ ivas_error stereo_memory_dec_fx( move16(); #if 1 // TODO: To be removed later - fd_bwe_dec_init_flt( st->hBWE_FD ); + //fd_bwe_dec_init_flt( st->hBWE_FD ); #endif - + fd_bwe_dec_init(st, st->hBWE_FD); st->hBWE_FD->old_wtda_swb_fx_exp = 0; st->hBWE_FD->mem_imdct_exp_fx = 0; st->prev_Q_synth = 0; @@ -1716,7 +1708,7 @@ ivas_error stereo_memory_dec_fx( IF ( EQ_16(hCPE->last_element_mode, IVAS_CPE_DFT) ) { - cpy_tcx_ltp_data( hCPE->hStereoDft->hTcxLtpDec, &tcxLtpTmp, output_Fs ); + cpy_tcx_ltp_data_fx( hCPE->hStereoDft->hTcxLtpDec, &tcxLtpTmp, output_Fs ); } /* deallocate data structure of the previous CPE mode */ @@ -1811,11 +1803,11 @@ ivas_error stereo_memory_dec_fx( { IF ( EQ_16(hCPE->nchan_out, 1) ) { - cpy_tcx_ltp_data( hCPE->hCoreCoder[0]->hTcxLtpDec, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); + cpy_tcx_ltp_data_fx( hCPE->hCoreCoder[0]->hTcxLtpDec, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); } ELSE { - cpy_tcx_ltp_data( &tcxLtpTmp, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); + cpy_tcx_ltp_data_fx( &tcxLtpTmp, hCPE->hCoreCoder[1]->hTcxLtpDec, output_Fs ); } } @@ -1907,9 +1899,9 @@ ivas_error stereo_memory_dec_fx( move16(); #if 1 // TODO: To be removed later - fd_bwe_dec_init_flt( st->hBWE_FD ); + //fd_bwe_dec_init_flt( st->hBWE_FD ); #endif - + fd_bwe_dec_init(st, st->hBWE_FD); st->hBWE_FD->old_wtda_swb_fx_exp = 0; st->hBWE_FD->mem_imdct_exp_fx = 0; st->prev_Q_synth = 0; @@ -2293,10 +2285,8 @@ void synchro_synthesis( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); } - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); for ( int p = 0; p < 111; p++ ) { @@ -2322,7 +2312,6 @@ void synchro_synthesis( hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); } } - hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[0]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; if ( !( ( hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_DFT && !( sba_dirac_stereo_flag && hCPE->hCoreCoder[0]->element_mode != IVAS_CPE_MDCT ) ) || ( hCPE->hCoreCoder[0]->element_mode == IVAS_CPE_DFT && hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ) ) { @@ -2334,7 +2323,6 @@ void synchro_synthesis( hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_out_32[p] / ( 1u << q ); } } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } #else @@ -2553,7 +2541,6 @@ void synchro_synthesis( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] = (Word32) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] * ( 1u << q ) ); } } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float * ONE_IN_Q15 ); hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain = (Word16) ( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float * ONE_IN_Q15 ); for ( int p = 0; p < 111; p++ ) { @@ -2573,7 +2560,6 @@ void synchro_synthesis( hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << q ); } } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; #else ivas_post_proc( NULL, hCPE, n, output[n], output, output_frame, 0 ); @@ -3128,7 +3114,6 @@ void synchro_synthesis_fx( { hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hStereoDft->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } } @@ -3153,7 +3138,6 @@ void synchro_synthesis_fx( { hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_float[p] = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_mem_in_32[p] / ( 1u << output_q ); } - hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_post_prev / ONE_IN_Q15; hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain_float = (float) hCPE->hCoreCoder[n]->hTcxLtpDec->tcxltp_gain / ONE_IN_Q15; } FOR( Word32 k = 0; k < NS2SA( 48000, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); k++ ) diff --git a/lib_dec/ivas_tcx_core_dec.c b/lib_dec/ivas_tcx_core_dec.c index 2a4e4f5b371e61b9e103f870bcaa11dab2e2a356..72be328e82d6dfc9b5bd92379a627ff45b2ca2f2 100644 --- a/lib_dec/ivas_tcx_core_dec.c +++ b/lib_dec/ivas_tcx_core_dec.c @@ -862,11 +862,11 @@ void stereo_tcx_core_dec_fx( { Word16 buffer[L_FRAME16k]; lerp( signal_outFB_fx, buffer, st->L_frame, hTcxDec->L_frameTCX ); - ApplyFdCng_fx( buffer, 0 /* Q of buffer */, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( buffer, 0 /* Q of buffer */, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } ELSE { - ApplyFdCng_fx( signal_out_fx, 0, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } } @@ -894,7 +894,7 @@ void stereo_tcx_core_dec_fx( IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 0 ) ) { - ApplyFdCng_fx( signal_out_fx, 0, NULL, NULL, NULL, NULL, st, st->bfi, 0 ); + ApplyFdCng_fx( signal_out_fx, 0, NULL, 0, NULL, NULL, NULL, st, st->bfi, 0 ); } } diff --git a/lib_dec/ivas_td_low_rate_dec.c b/lib_dec/ivas_td_low_rate_dec.c index 2b1d358d7106c02b47d3e8f1053a3e8cf11c16d7..6d4dca335fc99a673f8d32efdd04af1a7b3e2ec1 100644 --- a/lib_dec/ivas_td_low_rate_dec.c +++ b/lib_dec/ivas_td_low_rate_dec.c @@ -357,7 +357,7 @@ void tdm_low_rate_dec_fx( * * Decode generic (GC), 2 subframes mode *---------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void decod_gen_2sbfr( Decoder_State *st, /* i/o: decoder static memory */ const int16_t sharpFlag, /* i : formant sharpening flag */ @@ -543,7 +543,7 @@ void decod_gen_2sbfr( /*hGSCDec end*/ #endif } - +#endif #ifdef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------* * decod_gen_2sbfr_ivas_fx() @@ -717,7 +717,8 @@ void decod_gen_2sbfr_ivas_fx( } /* SC-VBR */ - st->prev_gain_pit_dec = gain_pit; + //st->prev_gain_pit_dec = gain_pit; + st->prev_gain_pit_dec_fx = gain_pit; return; } diff --git a/lib_dec/post_dec.c b/lib_dec/post_dec.c index 120046fa8be01e42847eb78011d7480a74fa4b50..2dd470cc33c7c23fa3391ca5e7cadc29fd9280ab 100644 --- a/lib_dec/post_dec.c +++ b/lib_dec/post_dec.c @@ -340,6 +340,7 @@ static void bass_pf_1sf_delay( return; } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------------------* * cldfb_synth_set_bandsToZero_flt() * @@ -474,3 +475,4 @@ void cldfb_synth_set_bandsToZero_flt( return; } +#endif diff --git a/lib_dec/rst_dec.c b/lib_dec/rst_dec.c index 4206f56521bd9ccbd509b0e6e370102adf4cd923..f3b744c7be5b3756f996c27c703f60857b81aa9b 100644 --- a/lib_dec/rst_dec.c +++ b/lib_dec/rst_dec.c @@ -47,7 +47,7 @@ * * Reset decoder static variables in case of CNG frame *----------------------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void CNG_reset_dec( Decoder_State *st, /* i/o: decoder state structure */ float *pitch_buf, /* o : floating pitch for each subframe */ @@ -93,3 +93,4 @@ void CNG_reset_dec( return; } +#endif diff --git a/lib_dec/stat_dec.h b/lib_dec/stat_dec.h index 27a60c3cc9972403623af4df5418d406fd42c3df..f16f0cc5ebc45f306049e037542ee7f0b58115a4 100644 --- a/lib_dec/stat_dec.h +++ b/lib_dec/stat_dec.h @@ -192,10 +192,11 @@ typedef struct float lp_speech_float; Word32 lp_speech; /* format: Q9.23 */ + Word16 q_lp_speech; float lp_noise_float; Word32 lp_noise; /* format: Q9.23 */ - + Word16 q_lp_noise; float msPeriodogBuf_float[MSBUFLEN * NPART_SHAPING]; @@ -560,7 +561,10 @@ typedef struct tcx_ltp_dec_structure int16_t tcxltp_pitch_int_post_prev; int16_t tcxltp_pitch_fr_post_prev; +//#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) +#if 1 float tcxltp_gain_post_prev_float; +#endif // #if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) Word16 tcxltp_gain_post_prev; int16_t tcxltp_filt_idx_prev; @@ -651,7 +655,7 @@ typedef struct tcx_dec_structure /* state variables for the minimum statistics used for PLC */ float NoiseLevelMemory_bfi[PLC_MIN_STAT_BUFF_SIZE]; #ifdef IVAS_FLOAT_FIXED - Word16 NoiseLevelMemory_bfi_fx[PLC_MIN_STAT_BUFF_SIZE]; + //Word16 NoiseLevelMemory_bfi_fx[PLC_MIN_STAT_BUFF_SIZE]; #endif // IVAS_FLOAT_FIXED int16_t NoiseLevelIndex_bfi; int16_t CurrLevelIndex_bfi; @@ -709,28 +713,40 @@ typedef struct gsc_dec_structure int16_t cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ //Word16 cor_strong_limit; /* AC mode (GSC) - Indicator about high spectral correlation per band */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_y_gain[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ +#endif Word16 old_y_gain_fx[MBANDS_GN16k]; /* AC mode (GSC) - AR mem for low rate gain quantization */ int16_t noise_lev; /* AC mode (GSC) - noise level */ //Word16 noise_lev; /* AC mode (GSC) - noise level Q0*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float lt_ener_per_band[MBANDS_GN16k]; +#endif Word16 lt_ener_per_band_fx[MBANDS_GN16k]; /* Q12 */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float Last_frame_ener; /* AC mode (GSC) - last frame energy */ +#endif Word32 Last_frame_ener_fx; /* AC mode (GSC) - last frame energy */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float Last_GSC_spectrum[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ +#endif Word16 Last_GSC_spectrum_fx[L_FRAME16k]; /* AC mode (GSC) - Last good GSC spectrum */ int16_t Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index */ //Word16 Last_GSC_pit_band_idx; /* AC mode (GSC) - Last pitch band index Q0*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_exc_dct_in[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ +#endif Word16 last_exc_dct_in_fx[L_FRAME16k]; /* AC mode (GSC) - previous excitation */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_ener; /* AC mode (GSC) - previous energy */ +#endif Word16 last_ener_fx; /* AC mode (GSC) - previous energy */ int16_t last_bitallocation_band[6]; /* AC mode (GSC) - previous bit allocation of each band */ @@ -1354,22 +1370,28 @@ typedef struct zero_bwe_dec_structure { int16_t seed2; /* HF (6-7kHz) BWE - seed for random signal generator */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_hp400[4]; /* HF (6-7kHz) BWE - hp400 filter memory */ - Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ float mem_hf[( L_FIR - 1 )]; /* HF (6-7kHz) BWE - band-pass filter memory */ - Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ float mem_syn_hf[M]; /* HF (6-7kHz) BWE - synthesis filter memory */ - Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ float delay_syn_hf[NS2SA( 16000, DELAY_CLDFB_NS )]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis */ - Word16 delay_syn_hf_fx[NS2SA(16000, DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ float mem_hp_interp[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ - Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ +#endif + Word16 mem_hp400_fx[6]; /* HF (6-7kHz) BWE - hp400 filter memory */ + Word16 q_mem_hp400_fx; + Word16 mem_hf_fx[2 * L_FILT16k]; /* HF (6-7kHz) BWE - band-pass filter memory Q(-2-memExp1)*/ + + Word16 mem_syn_hf_fx[M]; /* HF (6-7kHz) BWE - synthesis filter memory Q0*/ + + Word16 delay_syn_hf_fx[NS2SA(16000, DELAY_CLDFB_NS)]; /* HF (6-7kHz) BWE - To synchronise BWE content with postfiltered synthesis Q0*/ + + Word16 mem_hp_interp_fx[INTERP_3_1_MEM_LEN]; /* HF (6-7 kHz) BWE - interp. memory */ } ZERO_BWE_DEC_DATA, *ZERO_BWE_DEC_HANDLE; @@ -1601,28 +1623,40 @@ typedef struct fd_bwe_dec_structure { Word16 old_wtda_wb_fx_exp; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_wtda_swb[L_FRAME48k]; +#endif Word16 L_old_wtda_swb_fx[L_FRAME48k]; Word32 L_old_wtda_swb_fx32[L_FRAME48k]; Word16 old_wtda_swb_fx_exp; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float old_syn_12k8_16k[NS2SA( 16000, DELAY_FD_BWE_ENC_NS )]; +#endif Word16 old_syn_12k8_16k_fx[NS2SA(16000, DELAY_FD_BWE_ENC_NS)]; /*Q_syn2-1*/ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_deemph_old_syn; +#endif Word16 mem_deemph_old_syn_fx; int16_t prev_mode; //Word16 prev_mode; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_SWB_fenv[SWB_FENV]; +#endif //Word16 prev_SWB_fenv_fx[SWB_FENV]; // Don't use this. Use prev_SWB_fenv_fx present in Decoder_State +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_Energy; +#endif Word16 prev_Energy_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_Energy_wb; +#endif Word32 prev_Energy_wb_fx; int16_t prev_L_swb_norm; @@ -1636,24 +1670,34 @@ typedef struct fd_bwe_dec_structure int16_t prev_frica_flag; //Word16 prev_frica_flag; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float mem_imdct[L_FRAME48k]; +#endif Word16 mem_imdct_fx[L_FRAME48k]; Word16 mem_imdct_exp_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_td_energy; +#endif Word16 prev_td_energy_fx; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_weight; +#endif Word16 prev_weight_fx; int16_t prev_flag; //Word16 prev_flag; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float last_wb_bwe_ener; +#endif //Word16 last_wb_bwe_ener_fx; // Don't use this. Use last_wb_bwe_ener_fx present in Decoder_State +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) float prev_fb_ener_adjust; +#endif //Word16 prev_fb_ener_adjust_fx; // Don't use this. Use prev_fb_ener_adjust_fx present in Decoder_State //Word16 prev_frame_pow_exp; @@ -1942,14 +1986,16 @@ typedef struct Decoder_State int16_t safety_net; //Word16 safety_net; - float stab_fac_smooth_lt; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float stab_fac_smooth_lt; float log_energy_old; + float log_energy_diff_lt; +#endif #ifdef IVAS_FLOAT_FIXED Word32 log_energy_diff_lt_fx;/*In range of word16*//*Q-15*/ Word16 stab_fac_smooth_lt_fx;/*In range of word16*//*Q-15*/ Word32 log_energy_old_fx; #endif - float log_energy_diff_lt; Word32 offset_scale1_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 1st 8-dim subvector*/ Word32 offset_scale2_fx[MAX_NO_MODES + 1][MAX_NO_SCALES + 1]; /* offsets for LSF LVQ structure 2nd 8-dim subvector*/ @@ -1974,7 +2020,7 @@ typedef struct Decoder_State float gc_threshold; /* Noise enhancer - threshold for gain_code */ Word32 gc_threshold_fx; /* Noise enhancer - threshold for gain_code Q16*/ - float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ + float dispMem[8]; /* Noise enhancer - phase dispersion algorithm memory */ struct dispMem_fx dm_fx; /* Noise enhancer - phase dispersion algorithm memory */ ZERO_BWE_DEC_HANDLE hBWE_zero; /* HF (6-7kHz) BWE */ @@ -1988,21 +2034,23 @@ typedef struct Decoder_State int16_t act_count; /* Stationary noise UV modification - activation counter */ //Word16 act_count; /* Stationary noise UV modification - activation counter Q0*/ - float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ Word32 ge_sm_fx; /* Stationary noise UV modification - smoothed excitation gain Q(GE_SHIFT)*/ - float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ Word16 lspold_s_fx[M]; /* Stationary noise UV modification - old LSP vector Q15*/ int16_t noimix_seed; /* Stationary noise UV modification - mixture seed */ //Word16 noimix_seed; /* Stationary noise UV modification - mixture seed Q0*/ - float min_alpha; /* Stationary noise UV modification - minimum alpha */ Word16 min_alpha_fx; /* Stationary noise UV modification - minimum alpha Q15*/ Word16 Q_stat_noise; /* Q of Exc_pe */ - float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float min_alpha; /* Stationary noise UV modification - minimum alpha */ + float lspold_s[M]; /* Stationary noise UV modification - old LSP vector */ + float ge_sm; /* Stationary noise UV modification - smoothed excitation gain */ + float exc_pe; /* Stationary noise UV modification - memory of the preemphasis filter */ +#endif // 0 Word16 exc_pe_fx; /* Stationary noise UV modification - scale (Q_stat_noise) */ Word16 Q_stat_noise_ge; /* Q of ge_sm_fx */ @@ -2106,17 +2154,19 @@ typedef struct Decoder_State int16_t last_active_bandsToZero_bwdec; int16_t last_flag_filter_NB; - float perc_bwddec_float; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float perc_bwddec_float; + float avg_nrg_LT_float; + float ng_ener_ST; /* Noise gate - short-term energy */ +#endif // 0 Word16 perc_bwddec; /*Q14*/ int16_t active_frame_cnt_bwddec; int16_t flag_buffer[20]; int16_t total_frame_cnt_bwddec; - float avg_nrg_LT_float; Word32 avg_nrg_LT; - float ng_ener_ST; /* Noise gate - short-term energy */ Word16 Ng_ener_ST_fx; /* Noise gate - short-term energy Q8*/ int16_t last_L_frame; /* ACELP@16kHz - last value of st->L_frame */ @@ -2199,10 +2249,12 @@ typedef struct Decoder_State int16_t nelp_mode_dec; //Word16 nelp_mode_dec; /* Q0 */ - float prev_gain_pit_dec; Word16 prev_gain_pit_dec_fx; /*Q14*/ - float prev_tilt_code_dec; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float prev_gain_pit_dec; + float prev_tilt_code_dec; +#endif Word16 prev_tilt_code_dec_fx; /*Q15*/ int16_t vbr_hw_BWE_disable_dec; @@ -2260,21 +2312,25 @@ typedef struct Decoder_State Word16 previoussynth_fx[L_FRAME48k]; Word32 previoussynth_fx_32[L_FRAME48k]; - float old_synth_sw[NS2SA( 48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS )]; /* note: buffer used only in EVS mono */ +//#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) +#if 1 + float old_synth_sw[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)]; /* note: buffer used only in EVS mono */ +#endif // 0 Word16 old_synth_sw_fx[NS2SA(48000, FRAME_SIZE_NS - ACELP_LOOK_NS - DELAY_BWE_TOTAL_NS)]; float delay_buf_out[HQ_DELTA_MAX * HQ_DELAY_COMP]; Word16 delay_buf_out_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q0*/ Word32 delay_buf_out32_fx[HQ_DELTA_MAX * HQ_DELAY_COMP]; /*Q11*/ -#ifdef IVAS_FLOAT_FIXED - //Word16 exp_delay_buf_out; -#endif + float old_Aq_12_8[M + 1]; /* old Aq[] for core switching */ Word16 old_Aq_12_8_fx[M + 1]; /* Q12 old Aq[] for core switching */ Word32 old_Aq_12_8_fx_32[M + 1]; /* Q28 old Aq[] for core switching */ - float old_Es_pred; /* old Es_pred for core switching */ +//#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) +#if 1 + float old_Es_pred; /* old Es_pred for core switching */ +#endif // 0 Word16 old_Es_pred_fx; /* old Es_pred for core switching */ // Word16 old_bfi_cnt; /* HQ core - # of bfi until previous frame(for FEC) */ @@ -2301,21 +2357,23 @@ typedef struct Decoder_State float tilt_swb; Word16 tilt_swb_fx; - float prev_ener_shb; +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) + float prev_ener_shb; + float prev_enerLH; + float prev_enerLL; +#endif Word16 prev_ener_shb_fx; float enerLH; Word32 enerLH_fx; Word16 enerLH_fx_Q; - float prev_enerLH; Word32 prev_enerLH_fx; float enerLL; Word32 enerLL_fx; Word16 enerLL_fx_Q; - float prev_enerLL; Word32 prev_enerLL_fx; int16_t prev_fractive; @@ -2454,36 +2512,39 @@ typedef struct Decoder_State int16_t L_frame_past; int16_t L_frameTCX_past; - float lsfold_uw_float[M]; /* old lsf (unweighted) */ Word16 lsfold_uw[M]; /* old lsf (unweighted) */ - float lspold_uw_float[M]; /* old lsp (unweighted) */ Word16 lspold_uw[M]; /* old lsp (unweighted) */ int16_t seed_tcx_plc; /* seed memory (for random function in TCX PLC) */ - float past_gpit_float; /* past gain of pitch (for frame recovery) */ - Word16 past_gpit; /* past gain of pitch (for frame recovery) */ - +//#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) +#if 1 + float lsfold_uw_float[M]; /* old lsf (unweighted) */ + float lspold_uw_float[M]; /* old lsp (unweighted) */ + float past_gpit_float; /* past gain of pitch (for frame recovery) */ float past_gcode_float; /* past energy (!) of code (for frame recovery) */ + float lsf_cng_float[M]; /* lsf coefficients used for CNG generation (long term) */ + float lspold_cng_float[M]; /* lsp coefficients used for CNG generation (long term) */ + float lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ + float old_lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ + float lsf_q_cng_float[M]; /* lsf coefficients used for CNG generation (short term interpolated) */ + float old_lsf_q_cng_float[M]; /* lsf: old quantized lsfs for background noise */ +#endif // 0 + + Word16 past_gpit; /* past gain of pitch (for frame recovery) */ Word32 past_gcode; /* past energy (!) of code (for frame recovery) */ /*15Q16*/ - float lsf_cng_float[M]; /* lsf coefficients used for CNG generation (long term) */ Word16 lsf_cng[M]; /* xSF coefficients used for CNG generation (long term) */ - float lspold_cng_float[M]; /* lsp coefficients used for CNG generation (long term) */ Word16 lspold_cng[M]; /* xSP coefficients used for CNG generation (long term) */ - float lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ Word16 lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - float old_lsp_q_cng_float[M]; /* lsp coefficients used for CNG generation (short term interpolated) */ Word16 old_lsp_q_cng[M]; /* xSP coefficients used for CNG generation (short term interpolated) */ - float lsf_q_cng_float[M]; /* lsf coefficients used for CNG generation (short term interpolated) */ Word16 lsf_q_cng[M]; /* xSF coefficients used for CNG generation (short term interpolated) */ - float old_lsf_q_cng_float[M]; /* lsf: old quantized lsfs for background noise */ Word16 old_lsf_q_cng[M]; /* xSF: old quantized lsfs for background noise */ float Aq_cng_float[( NB_SUBFR16k + 1 ) * ( M + 1 )]; /* LPC coefficients derived from CNG estimate */ @@ -2494,7 +2555,10 @@ typedef struct Decoder_State int16_t plcBackgroundNoiseUpdated; /* flag: Is background noise estimate updated? */ - float last_gain_syn_deemph_float; +//#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) +#if 1 + float last_gain_syn_deemph_float; +#endif Word16 last_gain_syn_deemph; /*Q15*/ Word16 last_gain_syn_deemph_e; diff --git a/lib_dec/stat_noise_uv_dec.c b/lib_dec/stat_noise_uv_dec.c index 58c40337d4b70e6ceab20fbf567b8a97867b2da0..ed0faa4b999894d7a5be7d575a4ff162db5f8a7c 100644 --- a/lib_dec/stat_noise_uv_dec.c +++ b/lib_dec/stat_noise_uv_dec.c @@ -38,7 +38,7 @@ #include "options.h" #include "prot.h" #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*---------------------------------------------------------* * stat_noise_uv_dec() * @@ -107,3 +107,4 @@ void stat_noise_uv_dec( return; } +#endif diff --git a/lib_dec/swb_bwe_dec.c b/lib_dec/swb_bwe_dec.c index 823506ead54e3ada6f46fad62a46e046bc0c76d1..a4bea1d4737e136bf722df7b64818b548cfdd870 100644 --- a/lib_dec/swb_bwe_dec.c +++ b/lib_dec/swb_bwe_dec.c @@ -49,7 +49,7 @@ #include "prot_fx1.h" #endif // IVAS_FLOAT_FIXED - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * para_pred_bws() * @@ -218,7 +218,7 @@ static int16_t para_pred_bws( return mode; } - +#endif #ifdef IVAS_FLOAT_FIXED static @@ -531,6 +531,7 @@ static int16_t WB_BWE_gain_deq( return ( mode ); } +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * wb_bwe_dec_flt() * @@ -640,6 +641,7 @@ void wb_bwe_dec_flt( return; } +#endif /*-------------------------------------------------------------------* * swb_bwe_gain_deq_flt() @@ -845,7 +847,7 @@ int16_t swb_bwe_gain_deq_flt( * * SWB BWE decoder *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void swb_bwe_dec_flt( Decoder_State *st, /* i/o: decoder state structure */ const float output[], /* i : synthesis @internal Fs */ @@ -1051,7 +1053,7 @@ void swb_bwe_dec_flt( return; } - +#endif #ifdef IVAS_FLOAT_FIXED @@ -1351,6 +1353,7 @@ Word16 swb_bwe_dec_fx32( #endif // IVAS_FLOAT_FIXED +#ifndef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * fd_bwe_dec_init_flt() * @@ -1382,6 +1385,7 @@ void fd_bwe_dec_init_flt( return; } +#endif #ifdef IVAS_FLOAT_FIXED void fd_bwe_dec_init_fx( diff --git a/lib_dec/swb_bwe_dec_hr.c b/lib_dec/swb_bwe_dec_hr.c index 8c0b1b2fd65b9a6442c321d007e5f06a6e253fa4..1a7ab3d1950607771bcc285945fd57ee124410f2 100644 --- a/lib_dec/swb_bwe_dec_hr.c +++ b/lib_dec/swb_bwe_dec_hr.c @@ -49,7 +49,7 @@ * * HR SWB BWE decoder *-------------------------------------------------------------------*/ - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) void swb_bwe_dec_hr( Decoder_State *st, /* i/o: decoder state structure */ const float *syn_12k8_16k, /* i : ACELP core synthesis @16kHz */ @@ -806,7 +806,7 @@ void swb_bwe_dec_hr( return; } - +#endif /*-------------------------------------------------------------------* * hr_bwe_dec_init_flt() * diff --git a/lib_dec/swb_tbe_dec.c b/lib_dec/swb_tbe_dec.c index 2a6858056aed079e0bf5226449bdc93e97d1c6af..5096ab9e496f14e7b7c72d99ee90d48d48b74c05 100644 --- a/lib_dec/swb_tbe_dec.c +++ b/lib_dec/swb_tbe_dec.c @@ -146,7 +146,7 @@ void ResetSHBbuffer_Dec( return; } - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * wb_tbe_dec() * @@ -445,7 +445,7 @@ void wb_tbe_dec( return; } - +#endif void calc_tilt_bwe_fx_loc( const Word32 *sp_fx, /* i : input signal */ Word32 *tilt_fx, /* o : signal tilt */ @@ -2630,7 +2630,7 @@ void ivas_swb_tbe_dec_fx( return; } #endif - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * swb_tbe_dec() * @@ -3720,7 +3720,7 @@ void swb_tbe_dec( return; } - +#endif /*-------------------------------------------------------------------* * Dequant_lower_LSF() * @@ -4584,7 +4584,9 @@ void TBEreset_dec( { if ( st->hBWE_FD != NULL ) { +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) st->hBWE_FD->prev_fb_ener_adjust = 0.0f; +#endif } set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER ); hBWE_TD->fb_tbe_demph = 0; diff --git a/lib_dec/updt_dec.c b/lib_dec/updt_dec.c index c7088ed2482b9a833c10eafb40ae152d4ff7e30e..3f37a73144e880505efcc0534f8aae1269066407 100644 --- a/lib_dec/updt_dec.c +++ b/lib_dec/updt_dec.c @@ -42,7 +42,7 @@ #include "cnst.h" #include #include "wmc_auto.h" - +#if (defined EVS_FLOAT) || !(defined IVAS_FLOAT_FIXED) /*-------------------------------------------------------------------* * updt_dec() * @@ -776,3 +776,4 @@ void update_decoder_LPD_cng_flt( return; } +#endif diff --git a/lib_dec/updt_dec_fx.c b/lib_dec/updt_dec_fx.c index 049dca937de510e1433a2922496a35dc2f1fa580..e24c95e12ad0e7bca2a85f97792b284acdb87687 100644 --- a/lib_dec/updt_dec_fx.c +++ b/lib_dec/updt_dec_fx.c @@ -964,8 +964,7 @@ void ivas_updt_dec_common_fx( Word32 log_energy_diff = L_abs(L_sub(st_fx->log_energy_old_fx , log_energy)); st_fx->log_energy_old_fx = log_energy; st_fx->log_energy_diff_lt_fx = Madd_32_16(Mpy_32_16_1(log_energy_diff, ENV_SMOOTH_FAC_FX ), st_fx->log_energy_diff_lt_fx, sub(MAX_16 , ENV_SMOOTH_FAC_FX)); - //To be deleted. - st_fx->log_energy_diff_lt = fixedToFloat(st_fx->log_energy_diff_lt_fx, Q15); + if (st_fx->core == HQ_CORE) { st_fx->stab_fac_fx = extract_l(L_min(MAX_16, L_add(L_shr(STAB_FAC_EST1_FX, Q15), Madd_32_32(L_shr(Mpy_32_16_1(STAB_FAC_EST2_FX , st_fx->hHQ_core->mem_env_delta), Q15), STAB_FAC_EST3_FX, st_fx->log_energy_diff_lt_fx)))); @@ -974,8 +973,6 @@ void ivas_updt_dec_common_fx( st_fx->stab_fac_smooth_lt_fx = extract_h(L_add(L_mult(ENV_SMOOTH_FAC_FX , st_fx->stab_fac_fx), L_mult(sub(MAX_16, ENV_SMOOTH_FAC_FX) , st_fx->stab_fac_smooth_lt_fx))); - //To be deleted - st_fx->stab_fac_smooth_lt = fixedToFloat(st_fx->stab_fac_smooth_lt_fx, Q15); } #endif IF( ((LE_32(st_fx->core_brate,SID_2k40))&&EQ_16(st_fx->cng_type,FD_CNG)) diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index eb3ce6ccfeb8cbc81dd4a726f8276755a62d2b65..6b7288af276fcb5fedf76110603bece439824e4b 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -59,7 +59,9 @@ #define SBA_CARDI_TARGET_ENERGY_GAIN 0.5f #define STEREO_PREPROCESS_IIR_FACTOR ( 0.9f ) - +#ifdef IVAS_FLOAT_FIXED +#define STEREO_PREPROCESS_IIR_FACTOR_Q15 (29491 ) +#endif /* powf(0.95f, 4.0f) for sub-frame smoothing instead of CLDFB slot */ #define ADAPT_HTPROTO_IIR_FAC 0.81450625f @@ -2057,10 +2059,44 @@ static void ivas_dirac_dec_binaural_process_output( offsetSamples = 0; nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; +#ifdef IVAS_FLOAT_FIXED + Word32 inRe_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], inIm_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 reverbRe_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word32 reverbIm_fx[BINAURAL_CHANNELS][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + Word16 q_inp[6][CLDFB_SLOTS_PER_SUBFRAME]; + Word16 q_inp_mix = 31; + + FOR( Word16 i = 0; i < BINAURAL_CHANNELS; i++ ) + FOR( Word16 i = 0; i < 6; i++ ) + { + FOR( Word16 j = 0; j < nSlots; j++ ) + { + floatToFixed_arrL( inRe[i][j], inRe_fx[i][j], Q6, nBins ); + floatToFixed_arrL( inIm[i][j], inIm_fx[i][j], Q6, nBins ); + } + } + q_inp_mix = Q6; +#endif + if ( processReverb ) { /* Process second / room effect part of binaural output when needed */ - ivas_binaural_reverb_processSubframe( hDiracDecBin->hReverb, numInChannels, nSlots, inRe, inIm, reverbRe, reverbIm ); +#ifdef IVAS_FLOAT_FIXED + ivas_binaural_reverb_processSubframe_fx( hDiracDecBin->hReverb, numInChannels, nSlots, inRe_fx, inIm_fx, reverbRe_fx, reverbIm_fx ); + FOR(Word16 i = 0; i < BINAURAL_CHANNELS; i++) + { + FOR(Word16 j = 0; j < nSlots; j++) + { + FOR(Word16 k = 0; k < nBins; k++) + { + reverbRe[i][j][k] = fix_to_float(reverbRe_fx[i][j][k], q_inp_mix); + reverbIm[i][j][k] = fix_to_float(reverbIm_fx[i][j][k], q_inp_mix); + } + } + } +#else + ivas_binaural_reverb_processSubframe( hDiracDecBin->hReverb, numInChannels, nSlots, inRe, inIm, reverbRe, reverbIm ); +#endif } interpVal = 0.0f; @@ -3015,6 +3051,345 @@ Word16 configure_reqularization_factor_fx( return reqularizationFactor; } #endif + +#ifdef IVAS_FLOAT_FIXED +/*-------------------------------------------------------------------* + * ivas_omasa_preProcessStereoTransportsForMovedObjects_fx() + * + * + *-------------------------------------------------------------------*/ + +void ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( + Decoder_Struct *st_ivas, + Word32 inRe_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word32 inIm_fx[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], + Word16 *cldfb_buf_q, + const Word16 nBins, + const Word16 subframe ) +{ + Word16 bin, ch, inCh, outCh, ismDirIndex, slot; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + MASA_ISM_DATA_HANDLE hMasaIsmData; + UWord8 enableCentering; + Word16 dirac_read_idx; + Word16 nSlots; + + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + hMasaIsmData = st_ivas->hMasaIsmData; + + IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA2 || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_HOA3 ) + { + enableCentering = 0; + move16(); + } + ELSE + { + enableCentering = 1; + move16(); + } + + /* Bypass processing until first object is moved */ + IF( EQ_16( hMasaIsmData->objectsMoved, 0 ) ) + { + FOR( ismDirIndex = 0; ismDirIndex < hSpatParamRendCom->numIsmDirections; ismDirIndex++ ) + { + IF( hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + hMasaIsmData->objectsMoved = 1; + move16(); + } + } + IF( EQ_16( hMasaIsmData->objectsMoved, 0 ) ) + { + /* No objects have moved so far */ + return; + } + } + + /* Perform object-movement based processing */ + nSlots = hSpatParamRendCom->subframe_nbslots[subframe]; + move16(); + dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; + move16(); + + FOR( bin = 0; bin < nBins; bin++ ) + { + Word16 ismPreprocMtxNew_fx[2][2]; + Word16 ismPreprocMtxIncrement_fx[2][2]; + Word16 eneMove_fx[2]; + Word16 enePreserve_fx[2]; + Word16 ismRatioAcc_fx; + Word32 subframeEne_fx; + Word32 Enes_fx[2]; + Word16 normEnes_fx[2]; + Word16 remainderNormEne_fx; + Word16 normEnes_q_fx[2], temp_q = 0, subframeEne_q_fx, ismRatioAcc_q_fx; + Word16 eneMove_q_fx[2], enePreserve_q_fx[2], temp1; + Word32 temp; + + set_s( ismPreprocMtxNew_fx[0], 0, 2 ); + set_s( ismPreprocMtxNew_fx[1], 0, 2 ); + set_s( ismPreprocMtxIncrement_fx[0], 0, 2 ); + set_s( ismPreprocMtxIncrement_fx[1], 0, 2 ); + set_s( eneMove_fx, 0, 2 ); + set_s( enePreserve_fx, 0, 2 ); + ismRatioAcc_fx = 0; + move16(); + subframeEne_fx = 0; + move32(); + set_s( normEnes_fx, 0, 2 ); + set_l( Enes_fx, 0, 2 ); + set_s( normEnes_q_fx, Q31, 2 ); + set_s( eneMove_q_fx, Q31, 2 ); + set_s( enePreserve_q_fx, Q31, 2 ); + + /* Determine transport normalized energies and subframe energy */ + FOR( slot = 0; slot < nSlots; slot++ ) + { + FOR( ch = 0; ch < 2; ch++ ) + { + Enes_fx[ch] = L_add( Enes_fx[ch], Mpy_32_32( inRe_fx[ch][slot][bin], inRe_fx[ch][slot][bin] ) ); + move32(); + Enes_fx[ch] = L_add( Enes_fx[ch], Mpy_32_32( inIm_fx[ch][slot][bin], inIm_fx[ch][slot][bin] ) ); // Q = *cldfb_buf_q + *cldfb_buf_q - 31 = -19 + move32(); + } + + subframeEne_fx = L_add( Enes_fx[0], Enes_fx[1] ); + subframeEne_q_fx = sub( add( *cldfb_buf_q, *cldfb_buf_q ), 31 ); // Q = -19 + + IF( NE_32( subframeEne_fx, 0 ) ) + { + normEnes_fx[0] = BASOP_Util_Divide3232_Scale( Enes_fx[0], subframeEne_fx, &temp_q ); + move32(); + normEnes_fx[0] = shr( normEnes_fx[0], sub( sub( 15, temp_q ), Q12 ) ); // Q12 + move32(); + normEnes_fx[1] = BASOP_Util_Divide3232_Scale( Enes_fx[1], subframeEne_fx, &temp_q ); + move32(); + normEnes_fx[1] = shr( normEnes_fx[1], sub( sub( 15, temp_q ), Q12 ) ); // Q12 + move32(); + } + ELSE + { + normEnes_fx[0] = BASOP_Util_Divide3232_Scale( Enes_fx[0], EPSILON_FX, &temp_q ); + move32(); + normEnes_fx[0] = shr( normEnes_fx[0], sub( sub( 15, temp_q ), Q12 ) ); // Q12 + move32(); + normEnes_fx[1] = BASOP_Util_Divide3232_Scale( Enes_fx[1], EPSILON_FX, &temp_q ); + move32(); + normEnes_fx[1] = shr( normEnes_fx[1], sub( sub( 15, temp_q ), Q12 ) ); // Q12 + move32(); + } + + + /* For each ismDir, formulate a mix-matrix that moves object audio signals between + * left and right channels when needed. Make a combined matrix by a ratio-weighted sum */ + FOR( ismDirIndex = 0; ismDirIndex < hSpatParamRendCom->numIsmDirections; ismDirIndex++ ) + { + Word16 panGainsOut_fx[2]; + Word16 panGainsIn_fx[2]; + Word16 ratio; + Word16 panEnesOut_fx[2]; + Word16 panEnesIn_fx[2]; + Word16 centeringFactor_fx; + + ratio = extract_l( hMasaIsmData->energy_ratio_ism_fx[ismDirIndex][dirac_read_idx][bin] ); // Q14 + ismRatioAcc_fx = add( ismRatioAcc_fx, ratio ); + ismRatioAcc_q_fx = Q14; + move16(); + + /* Get input and output panning gains */ + ivas_get_stereo_panning_gains_fx( hMasaIsmData->azimuth_ism[ismDirIndex][dirac_read_idx], + hMasaIsmData->elevation_ism[ismDirIndex][dirac_read_idx], + panGainsIn_fx ); + + IF( hMasaIsmData->ism_is_edited[ismDirIndex] ) + { + ivas_get_stereo_panning_gains_fx( hMasaIsmData->azimuth_ism_edited[ismDirIndex], + hMasaIsmData->elevation_ism_edited[ismDirIndex], + panGainsOut_fx ); + } + ELSE + { + /* When not edited, input and output pan gains are the same */ + FOR( ch = 0; ch < 2; ch++ ) + { + panGainsOut_fx[ch] = panGainsIn_fx[ch]; + move16(); + } + } + + /* Determine pan enes */ + FOR( ch = 0; ch < 2; ch++ ) + { + panEnesOut_fx[ch] = mult( panGainsOut_fx[ch], panGainsOut_fx[ch] ); // Q15 + move16(); + panEnesIn_fx[ch] = mult( panGainsIn_fx[ch], panGainsIn_fx[ch] ); // Q15 + move16(); + } + + IF( enableCentering ) + { + centeringFactor_fx = s_max( 0, sub( mult( shl( 2, 13 ), abs_s( sub( panEnesIn_fx[0], panEnesOut_fx[0] ) ) ), ONE_IN_Q13 ) ); // Q13 + FOR( ch = 0; ch < 2; ch++ ) + { + panEnesOut_fx[ch] = mult( panEnesOut_fx[ch], sub( ONE_IN_Q13, centeringFactor_fx ) ); // Q13 + move16(); + panEnesOut_fx[ch] = add( panEnesOut_fx[ch], shr( centeringFactor_fx, 1 ) ); // Q13 + move16(); + } + } + + FOR( ch = 0; ch < 2; ch++ ) + { + Word16 eneMoveThis_fx; + Word16 enePreserveThis_fx; + + eneMoveThis_fx = s_max( 0, sub( shr( panEnesIn_fx[ch], 2 ), panEnesOut_fx[ch] ) ); // Q13 + enePreserveThis_fx = sub( shr( panEnesIn_fx[ch], 2 ), eneMoveThis_fx ); // Q13 + + eneMove_fx[ch] = mult( ratio, eneMoveThis_fx ); // Q = 14 + 13 - 15 = 12 + move16(); + enePreserve_fx[ch] = mult( ratio, enePreserveThis_fx ); // Q = 14 + 13 - 15 = 12 + move16(); + + /* Subtract object parts from normEnes */ + normEnes_fx[ch] = sub( normEnes_fx[ch], shr( mult( panEnesIn_fx[ch], ratio ), 2 ) ); // Q12 + move16(); + } + } + + /* Any remaining (non-object) energy is set to be preserved at both channels */ + remainderNormEne_fx = s_max( 0, sub( sub( shr( sub( ONE_IN_Q14, ismRatioAcc_fx ), sub( Q14, Q12 ) ), normEnes_fx[0] ), normEnes_fx[1] ) ); // Q12 + + FOR( ch = 0; ch < 2; ch++ ) + { + enePreserve_fx[ch] = add( enePreserve_fx[ch], s_max( 0, add( enePreserve_fx[ch], shr( remainderNormEne_fx, 1 ) ) ) ); // Q12 + move16(); + } + + /* Temporally average energy moving and preserving, and generate the transport signal preprocessing matrix */ + FOR( ch = 0; ch < 2; ch++ ) + { + Word32 normVal_fx; + hMasaIsmData->eneMoveIIR_fx[ch][bin] = Mpy_32_16_1( hMasaIsmData->eneMoveIIR_fx[ch][bin], STEREO_PREPROCESS_IIR_FACTOR_Q15 ); + move32(); + temp = Mpy_32_16_1( subframeEne_fx, eneMove_fx[ch] ); + hMasaIsmData->eneMoveIIR_fx[ch][bin] = L_add( hMasaIsmData->eneMoveIIR_fx[ch][bin], temp ); // Q = subframeEne_q_fx - 3 + move32(); + + hMasaIsmData->enePreserveIIR_fx[ch][bin] = Mpy_32_16_1( hMasaIsmData->enePreserveIIR_fx[ch][bin], STEREO_PREPROCESS_IIR_FACTOR_Q15 ); + move32(); + temp = Mpy_32_16_1( subframeEne_fx, enePreserve_fx[ch] ); + hMasaIsmData->enePreserveIIR_fx[ch][bin] = L_add( hMasaIsmData->enePreserveIIR_fx[ch][bin], temp ); // Q = subframeEne_q_fx - 3 + move32(); + + normVal_fx = L_add( hMasaIsmData->eneMoveIIR_fx[ch][bin], hMasaIsmData->enePreserveIIR_fx[ch][bin] ); + IF( NE_32( normVal_fx, 0 ) ) + { + + temp1 = BASOP_Util_Divide3232_Scale( hMasaIsmData->enePreserveIIR_fx[ch][bin], normVal_fx, &temp_q ); + ismPreprocMtxNew_fx[ch][ch] = Sqrt16( temp1, &temp_q ); + move16(); + ismPreprocMtxNew_fx[ch][ch] = shl( ismPreprocMtxNew_fx[ch][ch], temp_q ); // Q15 + move16(); + temp1 = BASOP_Util_Divide3232_Scale( hMasaIsmData->eneMoveIIR_fx[ch][bin], normVal_fx, &temp_q ); + ismPreprocMtxNew_fx[sub( 1, ch )][ch] = Sqrt16( temp1, &temp_q ); + move16(); + ismPreprocMtxNew_fx[sub( 1, ch )][ch] = shl( ismPreprocMtxNew_fx[sub( 1, ch )][ch], temp_q ); // Q15 + move16(); + } + ELSE + { + ismPreprocMtxNew_fx[ch][ch] = 0; + move16(); + ismPreprocMtxNew_fx[sub( 1, ch )][ch] = 0; + move16(); + } + } + + /* Get increment value for temporal interpolation */ + FOR( inCh = 0; inCh < 2; inCh++ ) + { + FOR( outCh = 0; outCh < 2; outCh++ ) + ismPreprocMtxIncrement_fx[outCh][inCh] = BASOP_Util_Divide1616_Scale( sub( ismPreprocMtxNew_fx[outCh][inCh], hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin] ), nSlots, &temp_q ); + move16(); + ismPreprocMtxIncrement_fx[outCh][inCh] = shl( ismPreprocMtxIncrement_fx[outCh][inCh], temp_q ); // Q15 + move16(); + } + } + + /* Mix signals */ + FOR( slot = 0; slot < nSlots; slot++ ) + { + Word16 eqVal_fx = 0; + Word16 eqVal_q_fx = 0; + Word32 outSlotRe_fx[2]; + Word32 outSlotIm_fx[2]; + + set_zero_fx( outSlotRe_fx, 2 ); + set_zero_fx( outSlotIm_fx, 2 ); + + FOR( outCh = 0; outCh < 2; outCh++ ) + { + FOR( inCh = 0; inCh < 2; inCh++ ) + { + hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin] = add( hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin], ismPreprocMtxIncrement_fx[outCh][inCh] ); // Q = 15 + move16(); + outSlotRe_fx[outCh] = Mpy_32_16_1( inRe_fx[inCh][slot][bin], hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin] ); // Q = *cldfb_buf_q = 6; + move32(); + outSlotIm_fx[outCh] = Mpy_32_16_1( inIm_fx[inCh][slot][bin], hMasaIsmData->ismPreprocMatrix_fx[outCh][inCh][bin] ); // Q = *cldfb_buf_q = 6; + move32(); + } + } + + /* IIR average the energy measures and determine and apply energy-preserving equalizer */ + hMasaIsmData->preprocEneTarget_fx[bin] = Mpy_32_16_1( hMasaIsmData->preprocEneTarget_fx[bin], STEREO_PREPROCESS_IIR_FACTOR_Q15 ); + move32(); + hMasaIsmData->preprocEneRealized_fx[bin] = Mpy_32_16_1( hMasaIsmData->preprocEneRealized_fx[bin], STEREO_PREPROCESS_IIR_FACTOR_Q15 ); + move32(); + FOR( ch = 0; ch < 2; ch++ ) + { + hMasaIsmData->preprocEneTarget_fx[bin] = L_add( hMasaIsmData->preprocEneTarget_fx[bin], Madd_32_32( Mpy_32_32( inRe_fx[ch][slot][bin], inRe_fx[ch][slot][bin] ), inIm_fx[ch][slot][bin], inIm_fx[ch][slot][bin] ) ); // Q= *cldfb_buf_q + *cldfb_buf_q - 31 = -19 + move32(); + hMasaIsmData->preprocEneRealized_fx[bin] = L_add( hMasaIsmData->preprocEneRealized_fx[bin], Madd_32_32( Mpy_32_32( outSlotRe_fx[ch], outSlotRe_fx[ch] ), outSlotIm_fx[ch], outSlotIm_fx[ch] ) ); // Q= *cldfb_buf_q + *cldfb_buf_q - 31 = -19 + move32(); + } + temp1 = BASOP_Util_Divide3232_Scale( hMasaIsmData->preprocEneTarget_fx[bin], L_max( EPSILON_FX, hMasaIsmData->preprocEneRealized_fx[bin] ), &eqVal_q_fx ); + eqVal_fx = Sqrt16( temp1, &eqVal_q_fx ); + temp1 = shl( 4, Q12 ); + IF( LT_16( eqVal_q_fx, Q12 ) ) + { + IF( GT_16( eqVal_fx, shr( temp1, sub( Q12, eqVal_q_fx ) ) ) ) + { + eqVal_fx = temp1; + move16(); + eqVal_q_fx = Q12; + move16(); + } + } + ELSE + { + IF( GT_16( shr( eqVal_fx, sub( eqVal_q_fx, Q12 ) ), temp1 ) ) + { + eqVal_fx = temp1; + move16(); + } + } + + FOR( ch = 0; ch < 2; ch++ ) + { + inRe_fx[ch][slot][bin] = Mpy_32_16_1( outSlotRe_fx[ch], eqVal_fx ); + move32(); + inIm_fx[ch][slot][bin] = Mpy_32_16_1( outSlotIm_fx[ch], eqVal_fx ); + move32(); + } + *cldfb_buf_q = sub( add( *cldfb_buf_q, eqVal_q_fx ), 15 ); + } + } + + return; +} +#endif /*-------------------------------------------------------------------* * ivas_omasa_preProcessStereoTransportsForMovedObjects() * diff --git a/lib_rend/ivas_dirac_output_synthesis_dec.c b/lib_rend/ivas_dirac_output_synthesis_dec.c index 7599eccbaf1ca0d9a8bec78331312f8d3678f0d9..a7da0434a4fb426d816594538b021850010e1c51 100644 --- a/lib_rend/ivas_dirac_output_synthesis_dec.c +++ b/lib_rend/ivas_dirac_output_synthesis_dec.c @@ -2989,7 +2989,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( } } - IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + IF( masa_band_mapping == NULL && EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { mvr2r_inc_fixed( direct_response_hoa_fx, 1, &hDirACRend->h_output_synthesis_psd_state.direct_responses_fx[k], hSpatParamRendCom->num_freq_bands, num_channels_dir ); @@ -3198,7 +3198,7 @@ void ivas_dirac_dec_compute_directional_responses_fx( FOR( l = 1; l < num_channels_dir; l++ ) { exp = 0; - var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), 31 - Q_surCohRatio, &exp ); + var_a = BASOP_Util_Add_Mant32Exp( ONE_IN_Q30, 1, L_negate( surCohRatio_fx[k] ), exp_surCohRatio, &exp ); var_b = Sqrt32( var_a, &exp ); direct_response_hoa_fx[l] = Mpy_32_32( direct_response_hoa_fx[l], var_b ); move32(); diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index 9fa8f396023865638574d49e5fc261b9b3aae1de..b190ac8a7bc9417c7dbc0411e33a5e0621b2fc25 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -44,6 +44,7 @@ #include "prot_fx1.h" #include "prot_fx2.h" #include "ivas_prot_fx.h" +#include "ivas_rom_binaural_crend_head.h" /*------------------------------------------------------------------------- * ivas_dirac_allocate_parameters() @@ -1448,6 +1449,7 @@ ivas_error ivas_dirac_alloc_mem( hDirAC_mem->direct_responses_square = NULL; #ifdef IVAS_FLOAT_FIXED hDirAC_mem->direct_responses_square_fx = NULL; + hDirAC_mem->proto_power_smooth_fx = NULL; #endif hDirAC_mem->frame_dec_f = NULL; if ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) @@ -1509,6 +1511,9 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.direct_responses_square = hDirAC_mem->direct_responses_square; #ifdef IVAS_FLOAT_FIXED hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx = hDirAC_mem->direct_responses_square_fx; + hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx = hDirAC_mem->proto_power_smooth_fx; + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = Q31; #endif /* Target and smoothed nrg factors/gains */ @@ -1586,11 +1591,16 @@ ivas_error ivas_dirac_alloc_mem( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx = hDirAC_mem->direct_responses_fx; + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; #endif /* Prototypes */ hDirAC_mem->proto_direct_buffer_f = NULL; hDirAC_mem->proto_diffuse_buffer_f = NULL; +#ifdef IVAS_FLOAT_FIXED + hDirAC_mem->proto_direct_buffer_f_fx = NULL; + hDirAC_mem->proto_diffuse_buffer_f_fx = NULL; +#endif if ( renderer_type != RENDERER_BINAURAL_PARAMETRIC && renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && renderer_type != RENDERER_STEREO_PARAMETRIC ) { if ( ( hDirAC_mem->proto_direct_buffer_f = (float *) malloc( sizeof( float ) * 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands ) ) == NULL ) @@ -1618,7 +1628,10 @@ ivas_error ivas_dirac_alloc_mem( } hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f = hDirAC_mem->proto_direct_buffer_f; hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f = hDirAC_mem->proto_diffuse_buffer_f; - +#ifdef IVAS_FLOAT_FIXED + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx = hDirAC_mem->proto_direct_buffer_f_fx; + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx = hDirAC_mem->proto_diffuse_buffer_f_fx; +#endif /* Gains/power factors*/ hDirAC_mem->direct_power_factor = NULL; hDirAC_mem->diffuse_power_factor = NULL; @@ -1750,6 +1763,10 @@ void ivas_dirac_free_mem_fx( { free(hDirAC_mem->proto_power_smooth); } + IF( hDirAC_mem->proto_power_smooth_fx != NULL ) + { + free( hDirAC_mem->proto_power_smooth_fx ); + } IF (hDirAC_mem->proto_power_diff_smooth != NULL) { free(hDirAC_mem->proto_power_diff_smooth); @@ -1790,10 +1807,18 @@ void ivas_dirac_free_mem_fx( { free(hDirAC_mem->proto_direct_buffer_f); } + IF( hDirAC_mem->proto_direct_buffer_f_fx != NULL ) + { + free( hDirAC_mem->proto_direct_buffer_f_fx ); + } IF (hDirAC_mem->proto_diffuse_buffer_f != NULL) { free(hDirAC_mem->proto_diffuse_buffer_f); } + IF( hDirAC_mem->proto_diffuse_buffer_f_fx != NULL ) + { + free( hDirAC_mem->proto_diffuse_buffer_f_fx ); + } IF (hDirAC_mem->direct_power_factor != NULL) { free(hDirAC_mem->direct_power_factor); @@ -1842,6 +1867,12 @@ void ivas_dirac_free_mem( { free( hDirAC_mem->proto_power_smooth ); } +#ifdef IVAS_FLOAT_FIXED + if ( hDirAC_mem->proto_power_smooth_fx != NULL ) + { + free( hDirAC_mem->proto_power_smooth_fx ); + } +#endif if ( hDirAC_mem->proto_power_diff_smooth != NULL ) { free( hDirAC_mem->proto_power_diff_smooth ); @@ -1870,6 +1901,20 @@ void ivas_dirac_free_mem( { free( hDirAC_mem->proto_direct_buffer_f ); } +#ifdef IVAS_FLOAT_FIXED + if ( hDirAC_mem->proto_direct_buffer_f_fx != NULL ) + { + free( hDirAC_mem->proto_direct_buffer_f_fx ); + } + if ( hDirAC_mem->proto_diffuse_buffer_f_fx != NULL ) + { + free( hDirAC_mem->proto_diffuse_buffer_f_fx ); + } + if (hDirAC_mem->direct_responses_fx != NULL) + { + free(hDirAC_mem->direct_responses_fx); + } +#endif if ( hDirAC_mem->proto_diffuse_buffer_f != NULL ) { free( hDirAC_mem->proto_diffuse_buffer_f ); @@ -1890,6 +1935,16 @@ void ivas_dirac_free_mem( { free( hDirAC_mem->onset_filter ); } +#ifdef IVAS_FLOAT_FIXED + if ( hDirAC_mem->reference_power_fx != NULL ) + { + free( hDirAC_mem->reference_power_fx ); + } + if ( hDirAC_mem->onset_filter_fx != NULL ) + { + free( hDirAC_mem->onset_filter_fx ); + } +#endif return; } @@ -2227,6 +2282,261 @@ void initDiffuseResponses_fx( } #endif +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * protoSignalComputation_shd_fx() + * + * + *-------------------------------------------------------------------------*/ + +void protoSignalComputation_shd_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *proto_diffuse_buffer_f_fx, + Word16 *proto_diffuse_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + const Word16 slot_index, + const Word16 num_inputs, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + Word32 *p_Rmat_fx, /* Q29*/ + Word16 q_cldfb ) +{ + Word16 l, k; + Word16 Rmat_k[4]; + Word32 *p_proto_direct_buffer_fx; + Word32 *p_proto_diffuse_buffer_fx; + Word32 re1, im1; + Word32 re2, im2; + Word32 re3, im3; + Word32 *p_k_fx[4]; + Word16 min_q_shift, q_shift; + Word16 idx, idx1; + + k = 0; /* to avoid compilation warning */ + move16(); + + min_q_shift = Q31; + move16(); + q_shift = Q31; + move16(); + + p_proto_direct_buffer_fx = proto_direct_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_inputs ) ); + p_proto_diffuse_buffer_fx = proto_diffuse_buffer_f_fx + i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); + + IF( EQ_16( num_inputs, 1 ) ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer_fx[i_mult( 2, l )] = RealBuffer_fx[0][0][l]; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = ImagBuffer_fx[0][0][l]; + move32(); + } + *proto_direct_buffer_f_q = q_cldfb; + move16(); + } + ELSE IF( EQ_16( num_inputs, 2 ) ) + { + IF( p_Rmat_fx != 0 ) + { + assert( EQ_16( num_inputs, 4 ) && "This code block should never be run with num_inputs != 4!" ); + + FOR( l = 0; l < num_freq_bands; l++ ) + { + re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + + re2 = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + im2 = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + + p_proto_direct_buffer_fx[i_mult( 2, l )] = re1; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = im1; + move32(); + p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_shl( Mpy_32_32( p_Rmat_fx[0], re2 ), 2 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_shl( Mpy_32_32( p_Rmat_fx[0], im2 ), 2 ); // left shift is done to maintain constant Q factor for p_proto_direct_buffer_fx + move32(); + } + *proto_direct_buffer_f_q = q_cldfb; + move16(); + } + ELSE + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + re1 = L_add( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + im1 = L_add( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + + p_proto_direct_buffer_fx[i_mult( 2, l )] = re1; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, l ), 1 )] = im1; + move32(); + p_proto_direct_buffer_fx[i_mult( 2, add( num_freq_bands, l ) )] = L_sub( RealBuffer_fx[0][0][l], RealBuffer_fx[1][0][l] ); + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, add( num_freq_bands, l ) ), 1 )] = L_sub( ImagBuffer_fx[0][0][l], ImagBuffer_fx[1][0][l] ); + move32(); + } + } + *proto_direct_buffer_f_q = q_cldfb; + move16(); + } + ELSE IF( GE_16( num_inputs, 4 ) ) + { + p_k_fx[0] = p_proto_direct_buffer_fx; + p_k_fx[1] = p_proto_direct_buffer_fx + i_mult( 2, num_freq_bands ); + p_k_fx[2] = p_proto_direct_buffer_fx + i_mult( 4, num_freq_bands ); + p_k_fx[3] = p_proto_direct_buffer_fx + i_mult( 6, num_freq_bands ); + + Rmat_k[0] = 0; + move16(); + Rmat_k[1] = 1; + move16(); + Rmat_k[2] = 2; + move16(); + Rmat_k[3] = 0; + move16(); + + /* calculate the minimum possible shift for the buffers RealBuffer_fx and ImagBuffer_fx */ + FOR( k = 0; k < 4; k++ ) + { + q_shift = L_norm_arr( RealBuffer_fx[k][0], num_freq_bands ); + min_q_shift = s_min( min_q_shift, q_shift ); + q_shift = L_norm_arr( ImagBuffer_fx[k][0], num_freq_bands ); + min_q_shift = s_min( min_q_shift, q_shift ); + } + + min_q_shift = sub( min_q_shift, 4 ); /* 4 is for guard bits*/ + + IF( p_Rmat_fx != 0 ) + { + assert( EQ_16( num_inputs, 4 ) && "This code block should never be run with num_inputs != 4!" ); + + FOR( l = 0; l < num_freq_bands; l++ ) + { + *p_k_fx[0] = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); + move32(); + reference_power_fx[add( l, num_freq_bands )] = Mpy_32_32( *p_k_fx[0], *p_k_fx[0] ); + move32(); + p_k_fx[0]++; + + *p_k_fx[0] = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); + move32(); + reference_power_fx[add( l, num_freq_bands )] = Madd_32_32( reference_power_fx[add( l, num_freq_bands )], *p_k_fx[0], *p_k_fx[0] ); + move32(); + p_k_fx[0]++; + + reference_power_fx[l] = L_shr( reference_power_fx[add( l, num_freq_bands )], 1 ); + move32(); + + FOR( k = 1; k < 4; k++ ) + { + re1 = L_shl( RealBuffer_fx[1][0][l], min_q_shift ); + re2 = L_shl( RealBuffer_fx[2][0][l], min_q_shift ); + re3 = L_shl( RealBuffer_fx[3][0][l], min_q_shift ); + im1 = L_shl( ImagBuffer_fx[1][0][l], min_q_shift ); + im2 = L_shl( ImagBuffer_fx[2][0][l], min_q_shift ); + im3 = L_shl( ImagBuffer_fx[3][0][l], min_q_shift ); + + idx = i_mult( 3, Rmat_k[k] ); + idx1 = add( l, i_mult( add( k, 1 ), num_freq_bands ) ); + + *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[add( idx, 1 )], re1 ), p_Rmat_fx[add( idx, 2 )], re2 ), p_Rmat_fx[idx], re3 ); + move32(); + *p_k_fx[k] = L_shl( *p_k_fx[k], 2 ); // left shift is done to maintain constant Q factor for p_k_fx + move32(); + reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); + move32(); + p_k_fx[k]++; + + *p_k_fx[k] = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[add( idx, 1 )], im1 ), p_Rmat_fx[add( idx, 2 )], im2 ), p_Rmat_fx[idx], im3 ); + move32(); + *p_k_fx[k] = L_shl( *p_k_fx[k], 2 ); // left shift is done to maintain constant Q factor + move32(); + reference_power_fx[idx1] = Mpy_32_32( *p_k_fx[k], *p_k_fx[k] ); + move32(); + p_k_fx[k]++; + + reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[idx1], 1 ) ); + move32(); + } + + *proto_direct_buffer_f_q = add( q_cldfb, min_q_shift ); + *reference_power_q = sub( add( *proto_direct_buffer_f_q, *proto_direct_buffer_f_q ), 31 ); + + FOR( k = 1; k < 4; k++ ) + { + RealBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); + move32(); + ImagBuffer_fx[k][0][l] = L_shr( p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )], sub( *proto_direct_buffer_f_q, q_cldfb ) ); + move32(); + } + } + } + ELSE + { + set_zero_fx( reference_power_fx, num_freq_bands ); + FOR( k = 0; k < 4; k++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )] = RealBuffer_fx[k][0][l]; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )] = ImagBuffer_fx[k][0][l]; + move32(); + + re1 = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); + im1 = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); + + reference_power_fx[add( l, i_mult( add( k, 1 ), num_freq_bands ) )] = Madd_32_32( Mpy_32_32( re1, re1 ), im1, im1 ); + move32(); + reference_power_fx[l] = L_add( reference_power_fx[l], L_shr( reference_power_fx[add( l, i_mult( add( k, 1 ), num_freq_bands ) )], 1 ) ); + move32(); + } + } + *proto_direct_buffer_f_q = q_cldfb; + move16(); + *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + } + + /* Additional transport channels = planar SBA components of degree higher than 1*/ + FOR( ; k < num_inputs; k++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_proto_direct_buffer_fx[i_mult( 2, add( i_mult( k, num_freq_bands ), l ) )] = RealBuffer_fx[k][0][l]; + move32(); + p_proto_direct_buffer_fx[add( i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ), 1 )] = ImagBuffer_fx[k][0][l]; + move32(); + } + } + } + + + /*Copy direct to diffuse proto*/ + Copy32( p_proto_direct_buffer_fx, p_proto_diffuse_buffer_fx, i_mult( i_mult( 2, num_freq_bands ), s_min( num_outputs_diff, num_inputs ) ) ); + *proto_diffuse_buffer_f_q = *proto_direct_buffer_f_q; + move16(); + + IF( EQ_16( num_inputs, 1 ) ) + { + /* Add comfort noise addition (CNA) to diffuse proto only*/ + FOR( l = 0; l < num_freq_bands; l++ ) + { + p_proto_diffuse_buffer_fx[i_mult( 2, l )] = L_add( p_proto_diffuse_buffer_fx[i_mult( 2, l )], RealBuffer_fx[1][0][l] ); + move32(); + p_proto_diffuse_buffer_fx[add( i_mult( 2, l ), 1 )] = L_add( p_proto_diffuse_buffer_fx[add( i_mult( 2, l ), 1 )], ImagBuffer_fx[1][0][l] ); + move32(); + } + } + + return; +} +#endif /*------------------------------------------------------------------------- * protoSignalComputation_shd() * @@ -2389,6 +2699,108 @@ void protoSignalComputation_shd( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * protoSignalComputation1_fx() + * + * + *-------------------------------------------------------------------------*/ + +void protoSignalComputation1_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_frame_f_fx, + Word16 *proto_frame_f_q, + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + Word32 *proto_power_smooth_fx, + Word16 *proto_power_smooth_q, + const Word16 slot_index, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + Word16 q_cldfb ) +{ + Word16 l, k, idx; + Word32 *p_proto_buffer_fx; + Word16 proto_power_smooth_fx_q, min_q_shift, q_shift; + Word32 re, im; + + min_q_shift = Q31; + move16(); + q_shift = Q31; + move16(); + + p_proto_buffer_fx = proto_direct_buffer_f_fx + i_mult( slot_index, i_mult( 2, num_freq_bands ) ); + + /* calculate the maximum shift possible for the bufferS RealBuffer_fx and ImagBuffer_fx*/ + q_shift = L_norm_arr( RealBuffer_fx[0][0], num_freq_bands ); + min_q_shift = s_min( q_shift, min_q_shift ); + q_shift = L_norm_arr( ImagBuffer_fx[0][0], num_freq_bands ); + min_q_shift = s_min( q_shift, min_q_shift ); + + min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); + + /* calculate the maximum shift possible for the buffer proto_power_smooth_fx */ + q_shift = getScaleFactor32( proto_power_smooth_fx, num_freq_bands ); + q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) ); + + Scale_sig32( proto_power_smooth_fx, num_freq_bands, q_shift ); + *proto_power_smooth_q = add( *proto_power_smooth_q, q_shift ); + proto_power_smooth_fx_q = *proto_power_smooth_q; + move16(); + + FOR( l = 0; l < num_freq_bands; l++ ) + { + re = L_shl( RealBuffer_fx[0][0][l], min_q_shift ); + im = L_shl( ImagBuffer_fx[0][0][l], min_q_shift ); + + reference_power_fx[l] = Madd_32_32( Mpy_32_32( re, re ), im, im ); + move32(); + *reference_power_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + + IF( LT_16( *reference_power_q, *proto_power_smooth_q ) ) + { + proto_power_smooth_fx[l] = L_add( L_shr( proto_power_smooth_fx[l], sub( *proto_power_smooth_q, *reference_power_q ) ), reference_power_fx[l] ); + move32(); + proto_power_smooth_fx_q = *reference_power_q; + move16(); + } + ELSE + { + proto_power_smooth_fx[l] = L_add( proto_power_smooth_fx[l], L_shr( reference_power_fx[l], sub( *reference_power_q, *proto_power_smooth_q ) ) ); + move32(); + proto_power_smooth_fx_q = *proto_power_smooth_q; + move16(); + } + + idx = i_mult( 2, l ); + p_proto_buffer_fx[idx] = RealBuffer_fx[0][0][l]; + move32(); + p_proto_buffer_fx[add( idx, 1 )] = ImagBuffer_fx[0][0][l]; + move32(); + + FOR( k = 0; k < num_outputs_diff; k++ ) + { + idx = add( i_mult( i_mult( 2, k ), num_freq_bands ), i_mult( 2, l ) ); + proto_frame_f_fx[idx] = RealBuffer_fx[0][0][l]; + move32(); + proto_frame_f_fx[add( idx, 1 )] = ImagBuffer_fx[0][0][l]; + move32(); + } + } + + *proto_frame_f_q = q_cldfb; + move16(); + *proto_direct_buffer_f_q = q_cldfb; + move16(); + *proto_power_smooth_q = proto_power_smooth_fx_q; + move16(); + + return; +} +#endif /*------------------------------------------------------------------------- * protoSignalComputation1() * @@ -2428,7 +2840,6 @@ void protoSignalComputation1( return; } - /*------------------------------------------------------------------------- * protoSignalComputation2() * @@ -2756,6 +3167,162 @@ void protoSignalComputation2( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * protoSignalComputation4_fx() + * + * + *-------------------------------------------------------------------------*/ + +void protoSignalComputation4_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_frame_f_fx, + Word16 *proto_frame_f_q, + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + Word32 *proto_power_smooth_fx, + Word16 *proto_power_smooth_q, + const Word16 slot_index, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + const Word32 *mtx_hoa_decoder, + const Word16 nchan_transport, + const Word16 *sba_map_tc_ind, + Word16 q_cldfb ) +{ + Word16 k, l, idx, idx2; + Word16 n, offset; + Word32 sq_tmp_fx; + Word32 *p_proto_buffer_fx; + Word16 min_q_shift, q_shift; + Word32 re, im; + Word16 proto_power_smooth_fx_q, sq_tmp_q; + + min_q_shift = Q31; + move16(); + q_shift = Q31; + move16(); + sq_tmp_q = 0; + move16(); + + set_zero_fx( reference_power_fx, num_freq_bands ); + + /* calculate the shift possible for both RealBuffer_fx and ImagBuffer_fx buffers*/ + FOR( k = 0; k < s_max( 4, nchan_transport ); k++ ) + { + q_shift = L_norm_arr( RealBuffer_fx[k][0], num_freq_bands ); + min_q_shift = s_min( q_shift, min_q_shift ); + q_shift = L_norm_arr( ImagBuffer_fx[k][0], num_freq_bands ); + min_q_shift = s_min( q_shift, min_q_shift ); + } + q_shift = min_q_shift; + min_q_shift = sub( min_q_shift, find_guarded_bits_fx( i_mult( 2, 4 ) ) ); + + FOR( k = 0; k < 4; k++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + re = L_shl( RealBuffer_fx[k][0][l], min_q_shift ); + im = L_shl( ImagBuffer_fx[k][0][l], min_q_shift ); + + sq_tmp_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); + + reference_power_fx[l] = Madd_32_16( reference_power_fx[l], sq_tmp_fx, 16384 ); // 16384 = 0.5 in Q15 + move32(); + } + } + sq_tmp_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + *reference_power_q = sub( add( sq_tmp_q, Q15 ), 15 ); + + min_q_shift = sub( q_shift, find_guarded_bits_fx( 2 ) ); + + /*For decorrelated diffuseness*/ + FOR( l = 0; l < num_outputs_diff; l++ ) + { + FOR( k = 0; k < num_freq_bands; k++ ) + { + idx = add( i_mult( i_mult( 2, l ), num_freq_bands ), i_mult( 2, k ) ); + proto_frame_f_fx[idx] = 0; + move32(); + proto_frame_f_fx[add( idx, 1 )] = 0; + move32(); + FOR( n = 0; n < nchan_transport; n++ ) + { + idx2 = add( i_mult( l, 16 ), sba_map_tc_ind[n] ); + + re = L_shl( RealBuffer_fx[n][0][k], min_q_shift ); + im = L_shl( ImagBuffer_fx[n][0][k], min_q_shift ); + + proto_frame_f_fx[idx] = Madd_32_32( proto_frame_f_fx[idx], re, mtx_hoa_decoder[idx2] ); + move32(); + proto_frame_f_fx[add( idx, 1 )] = Madd_32_32( proto_frame_f_fx[add( idx, 1 )], im, mtx_hoa_decoder[idx2] ); + move32(); + } + } + } + *proto_frame_f_q = sub( add( add( min_q_shift, q_cldfb ), Q29 ), 31 ); + + /* calculate the shift possible to up scale the buffer proto_power_smooth_fx*/ + min_q_shift = getScaleFactor32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ) ); + min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); + + Scale_sig32( proto_power_smooth_fx, i_mult( num_outputs_diff, num_freq_bands ), min_q_shift ); + *proto_power_smooth_q = add( *proto_power_smooth_q, min_q_shift ); + proto_power_smooth_fx_q = *proto_power_smooth_q; + move16(); + + /* calculate the shift possible to up scale the values of the buffer proto_frame_f_fx*/ + min_q_shift = getScaleFactor32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ) ); + min_q_shift = sub( min_q_shift, find_guarded_bits_fx( 2 ) ); + + Scale_sig32( proto_frame_f_fx, i_mult( 2, i_mult( num_outputs_diff, num_freq_bands ) ), min_q_shift ); + *proto_frame_f_q = add( *proto_frame_f_q, min_q_shift ); + + offset = i_mult( i_mult( slot_index, 2 ), i_mult( num_freq_bands, num_outputs_diff ) ); + p_proto_buffer_fx = proto_direct_buffer_f_fx + offset; + + FOR( k = 0; k < num_outputs_diff; k++ ) + { + FOR( l = 0; l < num_freq_bands; l++ ) + { + idx = i_mult( 2, add( i_mult( k, num_freq_bands ), l ) ); + + sq_tmp_fx = Madd_32_32( Mpy_32_32( proto_frame_f_fx[idx], proto_frame_f_fx[idx] ), proto_frame_f_fx[add( idx, 1 )], proto_frame_f_fx[add( idx, 1 )] ); + sq_tmp_q = sub( add( *proto_frame_f_q, *proto_frame_f_q ), 31 ); + + IF( LT_16( *proto_power_smooth_q, sq_tmp_q ) ) + { + proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )] = L_add( proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )], L_shr( sq_tmp_fx, sub( sq_tmp_q, *proto_power_smooth_q ) ) ); + move32(); + proto_power_smooth_fx_q = *proto_power_smooth_q; + move16(); + } + ELSE + { + proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )] = L_add( L_shr( proto_power_smooth_fx[add( l, i_mult( k, num_freq_bands ) )], sub( *proto_power_smooth_q, sq_tmp_q ) ), sq_tmp_fx ); + move32(); + proto_power_smooth_fx_q = sq_tmp_q; + move16(); + } + + p_proto_buffer_fx[idx] = proto_frame_f_fx[idx]; + move32(); + p_proto_buffer_fx[add( idx, 1 )] = proto_frame_f_fx[add( idx, 1 )]; + move32(); + } + } + + *proto_direct_buffer_f_q = *proto_frame_f_q; + move16(); + *proto_power_smooth_q = proto_power_smooth_fx_q; + move16(); + + return; +} +#else /*------------------------------------------------------------------------- * protoSignalComputation4() * @@ -2829,7 +3396,7 @@ void protoSignalComputation4( return; } - +#endif /*------------------------------------------------------------------------- * ivas_dirac_dec_compute_diffuse_proto() @@ -3196,6 +3763,154 @@ void computeIntensityVector_dec( } +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * ivas_lfe_synth_with_cldfb_fx() + * + * + *------------------------------------------------------------------------*/ + +void ivas_lfe_synth_with_cldfb_fx( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const Word16 slot_index, + const Word16 subframe_index, + const Word16 nchan_transport, + Word16 q_cldfb ) +{ + Word16 i; + + Word16 lfeGain_fx, transportGain_fx; + Word32 protoLfeReal_fx, protoLfeImag_fx; + Word32 transportEne_fx, protoLfeEne_fx, targetEneLfe_fx, targetEneTrans_fx; + Word16 transportEne_q, protoLfeEne_q, targetEneLfe_q, targetEneTrans_q; + Word16 temp, temp_q = 0; + Word16 transportGain_q_fx, lfeGain_q_fx; + Word16 exp, min_q_shift; + Word32 re, im; + + exp = Q31; + move16(); + min_q_shift = Q31; + move16(); + + set_zero_fx( RealBufferLfe_fx[slot_index], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( ImagBufferLfe_fx[slot_index], CLDFB_NO_CHANNELS_MAX ); + + FOR( i = 0; i < nchan_transport; i++ ) + { + IF( RealBuffer_fx[i][0][0] ) + { + exp = norm_l( RealBuffer_fx[i][0][0] ); + } + min_q_shift = s_min( min_q_shift, exp ); + IF( ImagBuffer_fx[i][0][0] ) + { + exp = norm_l( ImagBuffer_fx[i][0][0] ); + } + min_q_shift = s_min( min_q_shift, exp ); + } + min_q_shift = sub( sub( min_q_shift, find_guarded_bits_fx( nchan_transport ) ), 1 ); + + re = L_shl( RealBuffer_fx[0][0][0], min_q_shift ); + im = L_shl( ImagBuffer_fx[0][0][0], min_q_shift ); + + protoLfeReal_fx = re; + move32(); + protoLfeImag_fx = im; + move32(); + transportEne_fx = Madd_32_32( Mpy_32_32( re, re ), im, im ); + FOR( i = 1; i < nchan_transport; i++ ) + { + re = L_shl( RealBuffer_fx[i][0][0], min_q_shift ); + im = L_shl( ImagBuffer_fx[i][0][0], min_q_shift ); + + protoLfeReal_fx = L_add( protoLfeReal_fx, re ); + protoLfeImag_fx = L_add( protoLfeImag_fx, im ); + transportEne_fx = L_add( transportEne_fx, Madd_32_32( Mpy_32_32( re, re ), im, im ) ); + } + transportEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + + protoLfeEne_fx = Madd_32_32( Mpy_32_32( protoLfeReal_fx, protoLfeReal_fx ), protoLfeImag_fx, protoLfeImag_fx ); + protoLfeEne_q = sub( add( add( q_cldfb, min_q_shift ), add( q_cldfb, min_q_shift ) ), 31 ); + + targetEneLfe_fx = Mpy_32_16_1( transportEne_fx, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ); + targetEneLfe_q = sub( add( transportEne_q, Q14 ), 15 ); + + temp = s_max( sub( ONE_IN_Q14, hMasaLfeSynth->lfeToTotalEnergyRatio_fx[subframe_index] ), 164 ); // 164 = 0.01 in Q14 + targetEneTrans_fx = Mpy_32_16_1( transportEne_fx, temp ); + targetEneTrans_q = sub( add( transportEne_q, Q14 ), 15 ); + + hMasaLfeSynth->transportEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->transportEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->protoLfeEneSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->protoLfeEneSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->targetEneLfeSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneLfeSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + hMasaLfeSynth->targetEneTransSmooth_fx = Mpy_32_16_1( hMasaLfeSynth->targetEneTransSmooth_fx, MCMASA_LFE_SYNTH_ALPHA_Q15 ); + + hMasaLfeSynth->transportEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->transportEneSmooth_fx, sub( 31, hMasaLfeSynth->transportEneSmooth_q ), transportEne_fx, sub( 31, transportEne_q ), &temp_q ); + hMasaLfeSynth->transportEneSmooth_q = sub( 31, temp_q ); + + hMasaLfeSynth->protoLfeEneSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->protoLfeEneSmooth_fx, sub( 31, hMasaLfeSynth->protoLfeEneSmooth_q ), protoLfeEne_fx, sub( 31, protoLfeEne_q ), &temp_q ); + hMasaLfeSynth->protoLfeEneSmooth_q = sub( 31, temp_q ); + + hMasaLfeSynth->targetEneLfeSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneLfeSmooth_fx, sub( 31, hMasaLfeSynth->targetEneLfeSmooth_q ), targetEneLfe_fx, sub( 31, targetEneLfe_q ), &temp_q ); + hMasaLfeSynth->targetEneLfeSmooth_q = sub( 31, temp_q ); + + hMasaLfeSynth->targetEneTransSmooth_fx = BASOP_Util_Add_Mant32Exp( hMasaLfeSynth->targetEneTransSmooth_fx, sub( 31, hMasaLfeSynth->targetEneTransSmooth_q ), targetEneTrans_fx, sub( 31, targetEneTrans_q ), &temp_q ); + hMasaLfeSynth->targetEneTransSmooth_q = sub( 31, temp_q ); + + temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneLfeSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->protoLfeEneSmooth_fx ), &temp_q ); + temp_q = add( sub( hMasaLfeSynth->targetEneLfeSmooth_q, hMasaLfeSynth->protoLfeEneSmooth_q ), sub( Q15, temp_q ) ); + + exp = sub( Q15, temp_q ); + lfeGain_fx = Sqrt16( temp, &exp ); + lfeGain_q_fx = sub( Q15, exp ); + + IF( GT_32( L_shr( lfeGain_fx, sub( lfeGain_q_fx, Q14 ) ), ONE_IN_Q14 ) ) + { + lfeGain_fx = ONE_IN_Q14; + move16(); + lfeGain_q_fx = Q14; + move16(); + } + + temp = BASOP_Util_Divide3232_Scale( hMasaLfeSynth->targetEneTransSmooth_fx, L_add( EPSILON_FX, hMasaLfeSynth->transportEneSmooth_fx ), &temp_q ); + temp_q = add( sub( hMasaLfeSynth->targetEneTransSmooth_q, hMasaLfeSynth->transportEneSmooth_q ), sub( Q15, temp_q ) ); + + exp = sub( Q15, temp_q ); + transportGain_fx = Sqrt16( temp, &exp ); + transportGain_q_fx = sub( Q15, exp ); + + IF( GT_32( L_shr( transportGain_fx, sub( transportGain_q_fx, Q14 ) ), ONE_IN_Q14 ) ) + { + transportGain_fx = ONE_IN_Q14; + move16(); + transportGain_q_fx = Q14; + move16(); + } + + RealBufferLfe_fx[slot_index][0] = L_shr( Mpy_32_16_1( protoLfeReal_fx, lfeGain_fx ), add( min_q_shift, sub( lfeGain_q_fx, Q15 ) ) ); // q_cldfb + move32(); + ImagBufferLfe_fx[slot_index][0] = L_shr( Mpy_32_16_1( protoLfeImag_fx, lfeGain_fx ), add( min_q_shift, sub( lfeGain_q_fx, Q15 ) ) ); // q_cldfb + move32(); + + RealBuffer_fx[0][0][0] = L_shr( Mpy_32_16_1( RealBuffer_fx[0][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb + move32(); + ImagBuffer_fx[0][0][0] = L_shr( Mpy_32_16_1( ImagBuffer_fx[0][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb + move32(); + FOR( i = 1; i < nchan_transport; i++ ) + { + RealBuffer_fx[i][0][0] = L_shr( Mpy_32_16_1( RealBuffer_fx[i][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb + move32(); + ImagBuffer_fx[i][0][0] = L_shr( Mpy_32_16_1( ImagBuffer_fx[i][0][0], transportGain_fx ), sub( transportGain_q_fx, Q15 ) ); // Q = q_cldfb + move32(); + } + + return; +} +#else /*------------------------------------------------------------------------- * ivas_lfe_synth_with_cldfb() * @@ -3261,8 +3976,123 @@ void ivas_lfe_synth_with_cldfb( return; } +#endif + +#ifdef IVAS_FLOAT_FIXED +/*------------------------------------------------------------------------- + * rotateAziEle_DirAC_fx() + * + * Apply rotation to DirAC DOAs + *------------------------------------------------------------------------*/ + +void rotateAziEle_DirAC_fx( + Word16 *azi, /* i/o: array of azimuth values */ + Word16 *ele, /* i/o: array of elevation values */ + const Word16 band1, /* i : bands to work on (lower limit) */ + const Word16 band2, /* i : bands to work on (upper bound) */ + const Word32 *p_Rmat_fx /* i : pointer to real-space rotation matrix */ +) +{ + Word16 b; + Word32 dv_0_fx, dv_1_fx, dv_2_fx; + Word32 dv_r_0_fx, dv_r_1_fx, dv_r_2_fx, tmp, w_fx; + Word16 exp, temp; + Word32 *ptr_sin, *ptr_cos; + ptr_sin = &sine_table_Q31[180]; // sin[x] = sine_table_Q31[180 + x] + ptr_cos = cosine_table_Q31; + push_wmops( "rotateAziEle_DirAC" ); + + FOR( b = band1; b < band2; b++ ) + { + /*Conversion spherical to cartesian coordinates*/ + IF( GT_16( abs_s( ele[b] ), 180 ) ) + { + // cos(180 + x) = -cos(x) + w_fx = -ptr_cos[sub( abs_s( ele[b] ), 180 )]; // Q31 + move32(); + } + ELSE + { + w_fx = ptr_cos[abs_s( ele[b] )]; // Q31 + move32(); + } + + IF( GT_16( abs_s( azi[b] ), 180 ) ) + { + // cos(180 + x) = -cos(x) + tmp = -ptr_cos[sub( abs_s( azi[b] ), 180 )]; // Q31 + move32(); + } + ELSE + { + tmp = ptr_cos[abs_s( azi[b] )]; // Q31 + move32(); + } + + dv_0_fx = Mpy_32_32( w_fx, tmp ); // Q31 + + + IF( GT_16( azi[b], 180 ) ) + { + // sin(180 + x) = -sin(x) + tmp = -ptr_sin[sub( azi[b], 180 )]; // Q31 + move32(); + } + ELSE IF( LT_16( azi[b], -180 ) ) + { + // sin(-(180 + x)) = sin(180 + x) = sinx + tmp = ptr_sin[sub( abs_s( azi[b] ), 180 )]; // Q31 + move32(); + } + ELSE + { + tmp = ptr_sin[azi[b]]; // Q31 + move32(); + } + dv_1_fx = Mpy_32_32( w_fx, tmp ); // Q31 + + IF( GT_16( ele[b], 180 ) ) + { + // sin(180 + x) = -sin(x) + dv_2_fx = -ptr_sin[sub( ele[b], 180 )]; // Q31 + move32(); + } + ELSE IF( LT_16( ele[b], -180 ) ) + { + // sin(-(180 + x)) = -sin(180 + x) = sinx + dv_2_fx = ptr_sin[sub( abs_s( ele[b] ), 180 )]; // Q31 + move32(); + } + ELSE + { + dv_2_fx = ptr_sin[ele[b]]; // Q31 + move32(); + } + + dv_r_0_fx = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[0], dv_0_fx ), p_Rmat_fx[1], dv_1_fx ), p_Rmat_fx[2], dv_2_fx ); // Q29 + dv_r_1_fx = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[3], dv_0_fx ), p_Rmat_fx[4], dv_1_fx ), p_Rmat_fx[5], dv_2_fx ); // Q29 + dv_r_2_fx = Madd_32_32( Madd_32_32( Mpy_32_32( p_Rmat_fx[6], dv_0_fx ), p_Rmat_fx[7], dv_1_fx ), p_Rmat_fx[8], dv_2_fx ); // Q29 + + /*Conversion spherical to cartesian coordinates*/ + temp = BASOP_util_atan2( dv_r_1_fx, dv_r_0_fx, 0 ); // Q13 + azi[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0; + move16(); + + tmp = L_add( Mpy_32_32( dv_r_0_fx, dv_r_0_fx ), Mpy_32_32( dv_r_1_fx, dv_r_1_fx ) ); // Q27 + exp = sub( 31, Q27 ); + tmp = Sqrt32( tmp, &exp ); + temp = BASOP_util_atan2( dv_r_2_fx, tmp, sub( sub( 31, 29 ), exp ) ); // Q13 + ele[b] = shr( mult( temp, _180_OVER_PI_Q9 ), 7 ); // Q0 + move16(); + } + + pop_wmops(); + + return; +} +#endif /*------------------------------------------------------------------------- * rotateAziEle_DirAC() * diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index ac3284302e5155fd8af06810332d650230767065..b7c87441d07fe8bf5abfcdc97dccd1a87e96fda6 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -562,12 +562,29 @@ ivas_error ivas_td_binaural_renderer_unwrap( subframe_length = output_frame / num_subframes; +#ifdef IVAS_FLOAT_FIXED + Word32 output_fx_buf[MAX_OUTPUT_CHANNELS][L_FRAME48k]; + Word32 *output_fx[MAX_OUTPUT_CHANNELS]; + for (int i = 0; i < MAX_OUTPUT_CHANNELS; i++) + { + output_fx[i] = output_fx_buf[i]; + for (int j = 0; j < L_FRAME48k; j++) + { + output_fx[i][j] = floatToFixed(output[i][j], Q11); + } + } +#endif + c_indx = 0; for ( nS = 0; nS < num_src; nS++ ) { if ( !( ivas_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p = output[nS]; +#ifdef IVAS_FLOAT_FIXED + hBinRendererTd->Sources[c_indx]->InputFrame_p_fx = output_fx[nS]; + hBinRendererTd->Sources[c_indx]->InputFrame_p_q = Q11; +#endif hBinRendererTd->Sources[c_indx]->SrcRend_p->InputAvailable = TRUE; c_indx++; } @@ -585,10 +602,77 @@ ivas_error ivas_td_binaural_renderer_unwrap( } /* Update the listener's location/orientation */ +#ifdef IVAS_FLOAT_FIXED + Word16 tmp_headRotEnabled; + IVAS_QUATERNION* tmp_Quaternions; + IVAS_VECTOR3* tmp_Pos; + + tmp_headRotEnabled = 0; + move16(); + tmp_Quaternions = NULL; + tmp_Pos = NULL; + + IF(enableCombinedOrientation != NULL) + { + tmp_headRotEnabled = enableCombinedOrientation[hCombinedOrientationData->subframe_idx]; + move16(); + } + IF(Quaternions != NULL) + { + tmp_Quaternions = &Quaternions[hCombinedOrientationData->subframe_idx]; + } + IF(Pos != NULL) + { + tmp_Pos = &Pos[hCombinedOrientationData->subframe_idx]; + } + + // Float to fixed + float max_val = 0; + max_val = (float)max(max_val, fabs(tmp_Quaternions->w)); + max_val = (float)max(max_val, fabs(tmp_Quaternions->x)); + max_val = (float)max(max_val, fabs(tmp_Quaternions->y)); + max_val = (float)max(max_val, fabs(tmp_Quaternions->z)); + Word16 quat_q = Q_factor_L(max_val); + tmp_Quaternions->w_fx = float_to_fix(tmp_Quaternions->w, quat_q); + tmp_Quaternions->x_fx = float_to_fix(tmp_Quaternions->x, quat_q); + tmp_Quaternions->y_fx = float_to_fix(tmp_Quaternions->y, quat_q); + tmp_Quaternions->z_fx = float_to_fix(tmp_Quaternions->z, quat_q); + tmp_Quaternions->w_qfact = tmp_Quaternions->x_qfact = tmp_Quaternions->y_qfact = tmp_Quaternions->z_qfact = quat_q; + + Word16 pos_q = Q25; + tmp_Pos->x_fx = (Word32)float_to_fix(tmp_Pos->x, pos_q); + tmp_Pos->y_fx = (Word32)float_to_fix(tmp_Pos->y, pos_q); + tmp_Pos->z_fx = (Word32)float_to_fix(tmp_Pos->z, pos_q); + tmp_Pos->x_qfact = tmp_Pos->y_qfact = tmp_Pos->z_qfact = pos_q; + for (int i = 0; i < 3; i++) + { + hBinRendererTd->Listener_p->Front_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Front[i], Q30); + hBinRendererTd->Listener_p->Up_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Up[i], Q30); + hBinRendererTd->Listener_p->Right_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Right[i], Q30); + hBinRendererTd->Listener_p->Pos_q = pos_q; + hBinRendererTd->Listener_p->Pos_fx[i] = float_to_fix(hBinRendererTd->Listener_p->Pos[i], hBinRendererTd->Listener_p->Pos_q); + } + // end float to fix + + IF ( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, tmp_Quaternions, tmp_Pos ) ) != IVAS_ERR_OK ) + { + return error; + } + + // fix to float + for (int i = 0; i < 3; i++) + { + hBinRendererTd->Listener_p->Front[i] = fix_to_float(hBinRendererTd->Listener_p->Front_fx[i], Q30); + hBinRendererTd->Listener_p->Up[i] = fix_to_float(hBinRendererTd->Listener_p->Up_fx[i], Q30); + hBinRendererTd->Listener_p->Right[i] = fix_to_float(hBinRendererTd->Listener_p->Right_fx[i], Q30); + hBinRendererTd->Listener_p->Pos[i] = fix_to_float(hBinRendererTd->Listener_p->Pos_fx[i], hBinRendererTd->Listener_p->Pos_q); + } +#else if ( ( error = TDREND_Update_listener_orientation( hBinRendererTd, ( enableCombinedOrientation != NULL ) ? enableCombinedOrientation[hCombinedOrientationData->subframe_idx] : 0, ( Quaternions != NULL ) ? &Quaternions[hCombinedOrientationData->subframe_idx] : NULL, ( Pos != NULL ) ? &Pos[hCombinedOrientationData->subframe_idx] : NULL ) ) != IVAS_ERR_OK ) { return error; } +#endif if ( hReverb != NULL ) { @@ -647,10 +731,28 @@ ivas_error ivas_td_binaural_renderer_unwrap( } /* Render subframe */ +#ifdef IVAS_FLOAT_FIXED + ////// Float to fix ///// + FOR(Word16 i = 0; i < hBinRendererTd->NumOfSrcs; i++) + { + FOR (int j = 0; j < 3; j++) + { + hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p_fx[j] = float_to_fix(hBinRendererTd->Sources[i]->SrcSpatial_p->Pos_p[j], Q25); + } + } + IF ( ( error = TDREND_GetMix_fx( hBinRendererTd, output_fx, subframe_length, subframe_idx, ism_md_subframe_update ) ) != IVAS_ERR_OK ) + { + return error; + } + /////// Fix to float //////// + me2f_buf(output_fx[0], 31 - Q11, output[0], (subframe_idx + 1)*subframe_length); + me2f_buf(output_fx[1], 31 - Q11, output[1], (subframe_idx + 1)*subframe_length); +#else if ( ( error = TDREND_GetMix( hBinRendererTd, output, subframe_length, subframe_idx, ism_md_subframe_update ) ) != IVAS_ERR_OK ) { return error; } +#endif /* Advance subframe pointer */ c_indx = 0; @@ -659,6 +761,9 @@ ivas_error ivas_td_binaural_renderer_unwrap( if ( !( ivas_format == MC_FORMAT && nS == lfe_idx ) ) /* Skip LFE for MC */ { hBinRendererTd->Sources[c_indx]->InputFrame_p += subframe_length; +#ifdef IVAS_FLOAT_FIXED + hBinRendererTd->Sources[c_indx]->InputFrame_p_fx += subframe_length; +#endif c_indx++; } } @@ -672,6 +777,12 @@ ivas_error ivas_td_binaural_renderer_unwrap( /* add reverb to rendered signals */ v_add( reverb_signal[0], output[0], output[0], output_frame ); v_add( reverb_signal[1], output[1], output[1], output_frame ); +#ifdef IVAS_FLOAT_FIXED + for (int i = 0; i < output_frame; i++) + { + output_fx[0][i] = float_to_fix(output[0][i], Q11); + } +#endif } return IVAS_ERR_OK; diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 7371e258ceb5397afb75a741160b7741ef817376..d18ba58fd9911a0bb21a4aa880b5d9df4efb21df 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -416,7 +416,24 @@ void computeIntensityVector_dec( float *intensity_real_y, float *intensity_real_z ); - +#ifdef IVAS_FLOAT_FIXED +void protoSignalComputation_shd_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *proto_diffuse_buffer_f_fx, + Word16 *proto_diffuse_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + const Word16 slot_index, + const Word16 num_inputs, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + Word32 *p_Rmat_fx, + Word16 q_cldfb +); +#endif void protoSignalComputation_shd( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -430,6 +447,24 @@ void protoSignalComputation_shd( float *p_Rmat ); +#ifdef IVAS_FLOAT_FIXED +void protoSignalComputation1_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_frame_f_fx, + Word16 *proto_frame_f_q, + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + Word32 *proto_power_smooth_fx, + Word16 *proto_power_smooth_q, + const Word16 slot_index, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + Word16 q_cldfb +); +#endif void protoSignalComputation1( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -455,6 +490,27 @@ void protoSignalComputation2( MASA_STEREO_TYPE_DETECT *stereo_type_detect ); +#ifdef IVAS_FLOAT_FIXED +void protoSignalComputation4_fx( + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 *proto_frame_f_fx, + Word16 *proto_frame_f_q, + Word32 *proto_direct_buffer_f_fx, + Word16 *proto_direct_buffer_f_q, + Word32 *reference_power_fx, + Word16 *reference_power_q, + Word32 *proto_power_smooth_fx, + Word16 *proto_power_smooth_q, + const Word16 slot_index, + const Word16 num_outputs_diff, + const Word16 num_freq_bands, + const Word32 *mtx_hoa_decoder, + const Word16 nchan_transport, + const Word16 *sba_map_tc_ind, + Word16 q_cldfb +); +#else void protoSignalComputation4( float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -473,6 +529,7 @@ void protoSignalComputation4( const int16_t nchan_transport, const int16_t *sba_map_tc_ind ); +#endif void ivas_dirac_dec_compute_diffuse_proto( DIRAC_REND_HANDLE hDirACRend, @@ -503,6 +560,19 @@ void ivas_masa_stereotype_detection( MASA_STEREO_TYPE_DETECT *stereo_type_detect ); +#ifdef IVAS_FLOAT_FIXED +void ivas_lfe_synth_with_cldfb_fx( + MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, + Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 RealBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + Word32 ImagBufferLfe_fx[MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], + const Word16 slot_index, + const Word16 subframe_index, + const Word16 nchan_transport, + Word16 q_cldfb +); +#else void ivas_lfe_synth_with_cldfb( MCMASA_LFE_SYNTH_DATA_HANDLE hMasaLfeSynth, float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], @@ -513,7 +583,17 @@ void ivas_lfe_synth_with_cldfb( const int16_t subframe_index, const int16_t nchan_transport ); +#endif +#ifdef IVAS_FLOAT_FIXED +void rotateAziEle_DirAC_fx( + Word16 *azi, + Word16 *ele, + const Word16 band1, + const Word16 band2, + const Word32 *p_Rmat_fx +); +#endif void rotateAziEle_DirAC( int16_t *azi, int16_t *ele, @@ -1481,12 +1561,12 @@ void ivas_binaural_reverb_processSubframe( #ifdef IVAS_FLOAT_FIXED void ivas_binaural_reverb_processSubframe_fx( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ - const int16_t numInChannels, /* i : num inputs to be processed */ - const int16_t numSlots, /* i : number of slots to be processed */ + const Word16 numInChannels, /* i : num inputs to be processed */ + const Word16 numSlots, /* i : number of slots to be processed */ Word32 inReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : input CLDFB data real, Comment: This change swaps two first dimensions as first dimension is not constant. */ Word32 inImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : input CLDFB data imag */ - Word64 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ - Word64 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ + Word32 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ + Word32 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ ); #endif diff --git a/lib_rend/ivas_reverb.c b/lib_rend/ivas_reverb.c index beb5277a3f699ac8dd37e63300830fe5e693cf23..adf09cc7c44a832ec85383601051062a18b7cf87 100644 --- a/lib_rend/ivas_reverb.c +++ b/lib_rend/ivas_reverb.c @@ -46,6 +46,23 @@ #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) ) #define float_to_fixQ31( n ) ( round( n * 0x7fffffff ) ) #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) ) + +static Word16 wrap_rad_fixed( + Word32 angle /* Q13 */ ) +{ + Word32 L_tmp = angle; + /* Wrap azimuth value */ + while(L_tmp > EVS_PI_FX ) + { + L_tmp -= EVS_2PI_FX; + } + while (L_tmp <= -EVS_PI_FX) + { + L_tmp += EVS_2PI_FX; + } + + return extract_l(L_tmp); +} #endif /* The reverberator structure implemented here is described in detail in: @@ -263,6 +280,7 @@ static void ivas_binaural_reverb_setPreDelay( * *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED static void ivas_binaural_reverb_setReverbTimes( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ const int32_t output_Fs, /* i : sampling_rate */ @@ -305,17 +323,10 @@ static void ivas_binaural_reverb_setReverbTimes( hReverb->binauralCoherenceCrossmixGains[bin] = -sqrtf( fabsf( tmpVal ) ); } hReverb->binauralCoherenceDirectGains[bin] = sqrtf( 1.0f - fabsf( tmpVal ) ); -#ifdef IVAS_FLOAT_FIXED - hReverb->binauralCoherenceCrossmixGains_fx[bin] = (Word32) float_to_fixQ31( hReverb->binauralCoherenceCrossmixGains[bin] ); - hReverb->binauralCoherenceDirectGains_fx[bin] = (Word32) float_to_fixQ31( hReverb->binauralCoherenceDirectGains[bin] ); -#endif /* Determine attenuation factor that generates the appropriate energy decay according to reverberation time */ attenuationFactorPerSample = powf( 10.0f, -3.0f * ( 1.0f / ( (float) CLDFB_SLOTS_PER_SECOND * revTimes[bin] ) ) ); hReverb->loopAttenuationFactor[bin] = powf( attenuationFactorPerSample, hReverb->loopBufLength[bin] ); -#ifdef IVAS_FLOAT_FIXED - hReverb->loopAttenuationFactor_fx[bin] = (Word32) float_to_fixQ31( hReverb->loopAttenuationFactor[bin] ); -#endif attenuationFactorPerSampleSq = attenuationFactorPerSample * attenuationFactorPerSample; /* Design sparse decorrelation filters. The decorrelation filters, due to random procedures involved, @@ -343,10 +354,7 @@ static void ivas_binaural_reverb_setReverbTimes( /* Set the tapPointer to point to the determined sample at the loop buffer */ hReverb->tapPointersReal[bin][ch][tap] = &( hReverb->loopBufReal[bin][sample] ); hReverb->tapPointersImag[bin][ch][tap] = &( hReverb->loopBufImag[bin][sample] ); -#ifdef IVAS_FLOAT_FIXED - hReverb->tapPointersReal_fx[bin][ch][tap] = &( hReverb->loopBufReal_fx[bin][sample] ); - hReverb->tapPointersImag_fx[bin][ch][tap] = &( hReverb->loopBufImag_fx[bin][sample] ); -#endif + energyBuildup -= 1.0f; /* A tap is added, thus remove its energy from the buildup */ tap++; actualizedEnergy += 1.0f; @@ -360,13 +368,206 @@ static void ivas_binaural_reverb_setReverbTimes( hReverb->reverbEqGains[bin] = sqrtf( revEnes[bin] ); /* Determined reverb spectrum */ hReverb->reverbEqGains[bin] *= sqrtf( intendedEnergy / actualizedEnergy ); /* Correction of random effects at the decorrelator design */ hReverb->reverbEqGains[bin] *= sqrtf( 0.5f * ( 1.0f - attenuationFactorPerSampleSq ) ); /* Correction of IIR decay rate */ -#ifdef IVAS_FLOAT_FIXED - hReverb->reverbEqGains_fx[bin] = (Word32) float_to_fixQ31( hReverb->reverbEqGains[bin] ); -#endif } return; } +#endif + +#ifdef IVAS_FLOAT_FIXED +static void ivas_binaural_reverb_setReverbTimes_fx( + REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ + const Word32 output_Fs, /* i : sampling_rate */ + const Word32 *revTimes_fx, /* i : reverberation times T60 for each CLDFB bin in seconds */ + const Word32 *revEnes_fx /* i : spectrum for reverberated sound at each CLDFB bin */ +) +{ + int16_t bin, ch, tap, sample; + + Word32 binCenterFreq_fx, diffuseFieldICC_fx, tmpVal_fx, attenuationFactorPerSample_fx, L_tmp; + Word32 intendedEnergy_fx, actualizedEnergy_fx, energyBuildup_fx, currentEnergy_fx, attenuationFactorPerSampleSq_fx; + Word16 tmp, tmp_exp, diffuseFieldICC_exp, scale, tmpVal_exp, attenuationFactorPerSample_exp, attenuationFactorPerSampleSq_exp, energyBuildup_exp, currentEnergy_exp, intendedEnergy_exp, actualizedEnergy_exp; + Word16 sine_inp, norm, sub_res, sub_exp, div_exp1, div1, sine, binCenterFreq_exp; + Word16 reverb_exp = 0; + + hReverb->binRend_RandNext = (UWord16) BIN_REND_RANDOM_SEED; + hReverb->highestBinauralCoherenceBin = 0; + + FOR ( bin = 0; bin < hReverb->numBins; bin++ ) + { + /* Determine the diffuse field binaural coherence */ + Word16 exp; + tmp_exp = BASOP_Util_Add_MantExp(bin, 15, 1, 14, &tmp); + tmp = BASOP_Util_Divide3232_Scale(L_deposit_h(tmp), L_deposit_h(hReverb->numBins), &exp); + exp = exp + ( tmp_exp - 15); + L_tmp = Mpy_32_16_1(output_Fs, tmp); + binCenterFreq_exp = 31 + exp; + binCenterFreq_fx = L_shr(L_tmp, 1); // divide by 2 + IF ( bin == 0 ) + { + diffuseFieldICC_fx = 1073741824; // 2 ^ 30, Q30 + diffuseFieldICC_exp = 1; + } + ELSE IF ( BASOP_Util_Cmp_Mant32Exp(binCenterFreq_fx, binCenterFreq_exp, 2700, 31 ) == -1) + { + tmp = BASOP_Util_Divide3232_Scale(binCenterFreq_fx, 550, &scale); + exp = scale + ( binCenterFreq_exp - 31 ); + tmp = add(mult(EVS_PI_FX, tmp), EPSILLON_FX); // to avoid divide by 0 issue + tmp_exp = exp + 2; + + sine_inp = wrap_rad_fixed(L_shl(tmp, tmp_exp - 2)); + + sine = getSinWord16(sine_inp); // Q15 + div1 = BASOP_Util_Divide1616_Scale(sine, tmp, &scale); + div_exp1 = scale + ( 0 - tmp_exp); + + tmp = BASOP_Util_Divide3232_Scale(binCenterFreq_fx, 2700, &scale); + scale = scale + (binCenterFreq_exp - 31); + + L_tmp = L_sub(L_shl(1, (15 - scale)), tmp); + norm = norm_l(L_tmp); + + L_tmp = L_shl(L_tmp, norm); + sub_res = extract_h(L_tmp); + sub_exp = sub(scale, sub(norm, 16)); + + diffuseFieldICC_fx = L_deposit_h(mult(sub_res, div1)); + diffuseFieldICC_exp = div_exp1 + sub_exp; + + hReverb->highestBinauralCoherenceBin = bin; + } + ELSE + { + + diffuseFieldICC_fx = 0; + diffuseFieldICC_exp = 0; + } + + /* Mixing gains to generate a diffuse-binaural sound based on incoherent sound */ + + L_tmp = Mpy_32_32( diffuseFieldICC_fx, diffuseFieldICC_fx ); // square + L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_tmp), diffuseFieldICC_exp + diffuseFieldICC_exp, &scale); + L_tmp = Sqrt32(L_tmp, &scale); + tmpVal_fx = L_shr( BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_tmp), scale, &tmpVal_exp), 1 ); + + IF ( BASOP_Util_Cmp_Mant32Exp(diffuseFieldICC_fx, diffuseFieldICC_exp, 0, 0 ) == 1 ) + { + exp = tmpVal_exp; + L_tmp = Sqrt32( L_abs( tmpVal_fx ), &exp); + hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_shl(L_tmp, exp); // Q31 + } + ELSE + { + exp = tmpVal_exp; + L_tmp = Sqrt32(L_abs(tmpVal_fx), &exp); + hReverb->binauralCoherenceCrossmixGains_fx[bin] = L_negate(L_shl(L_tmp, exp)); // Q31 + } + + exp = tmpVal_exp; + L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(L_abs(tmpVal_fx)), tmpVal_exp, &exp); + L_tmp = Sqrt32(L_abs(L_tmp), &exp); + hReverb->binauralCoherenceDirectGains_fx[bin] = L_shl(L_tmp, exp); //making as Q31 + /* Determine attenuation factor that generates the appropriate energy decay according to reverberation time */ + + L_tmp = Mpy_32_32(1677721600, revTimes_fx[bin]); // e10 --> 800 * 2^21, + e0 + tmp = BASOP_Util_Divide3232_Scale(1073741824, L_tmp, &scale); + scale = scale + ( 1 - 10 ); + L_tmp = Mpy_32_16_1(-1610612736, tmp); // * -3 + scale = 2 + scale; + L_tmp = Mpy_32_32(1783446563, L_tmp); // scale + 2 + attenuationFactorPerSample_fx = BASOP_util_Pow2(L_tmp, scale + 2, &attenuationFactorPerSample_exp ); + + Word32 tmp_mul; + scale = norm_l(hReverb->loopBufLength[bin]); + tmp_mul = L_shl(hReverb->loopBufLength[bin], scale); + L_tmp = BASOP_Util_Log2( attenuationFactorPerSample_fx ); + L_tmp = L_add(L_tmp, attenuationFactorPerSample_exp * (1 << 25)); + L_tmp = Mpy_32_32(L_tmp, tmp_mul); + hReverb->loopAttenuationFactor_fx[bin] = BASOP_util_Pow2(L_tmp, 6 + 31 - scale, &exp); + hReverb->loopAttenuationFactor_fx[bin] = L_shl(hReverb->loopAttenuationFactor_fx[bin], exp); // making as Q31 + + attenuationFactorPerSampleSq_fx = Mpy_32_32( attenuationFactorPerSample_fx, attenuationFactorPerSample_fx ); + attenuationFactorPerSampleSq_exp = attenuationFactorPerSample_exp + attenuationFactorPerSample_exp; + + /* Design sparse decorrelation filters. The decorrelation filters, due to random procedures involved, + * may affect the spectrum of the output. The spectral effect is therefore monitored and compensated for. */ + + intendedEnergy_fx = 0; + intendedEnergy_exp = 0; + actualizedEnergy_fx = 0; + actualizedEnergy_exp = 0; + + FOR ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + + energyBuildup_fx = 0; + energyBuildup_exp = 0; + currentEnergy_fx = 1073741824; + currentEnergy_exp = 1; + + tap = 0; + + FOR ( sample = 0; sample < hReverb->loopBufLength[bin]; sample++ ) + { + intendedEnergy_fx = BASOP_Util_Add_Mant32Exp( intendedEnergy_fx, intendedEnergy_exp, currentEnergy_fx, currentEnergy_exp, &intendedEnergy_exp ); + /* The randomization at the energy build up affects where the sparse taps are located */ + + UWord16 ret_binRend = binRend_rand(hReverb); + + tmp = BASOP_Util_Divide3232_Scale(ret_binRend, PCM16_TO_FLT_FAC_FX, &tmp_exp); + L_tmp = BASOP_Util_Add_Mant32Exp(L_deposit_h(tmp), tmp_exp, L_negate(1073741824), 0, &exp); + L_tmp = Mpy_32_32(L_tmp, 214748364); // exp + 0 + L_tmp = BASOP_Util_Add_Mant32Exp(L_tmp, exp, currentEnergy_fx, currentEnergy_exp, &exp); + energyBuildup_fx = BASOP_Util_Add_Mant32Exp(energyBuildup_fx, energyBuildup_exp, L_tmp, exp, &energyBuildup_exp); + IF(BASOP_Util_Cmp_Mant32Exp(energyBuildup_fx, energyBuildup_exp, 0, 0) >= 0) /* A new filter tap is added at this condition */ + { + IF(BASOP_Util_Cmp_Mant32Exp(energyBuildup_fx, energyBuildup_exp, 1, 31) >= 0) { + /* Four efficient phase operations: n*pi/2, n=0,1,2,3 */ + hReverb->tapPhaseShiftType[bin][ch][tap] = (int16_t)(binRend_rand(hReverb) % 4); + /* Set the tapPointer to point to the determined sample at the loop buffer */ + + hReverb->tapPointersReal_fx[bin][ch][tap] = &(hReverb->loopBufReal_fx[bin][sample]); + hReverb->tapPointersImag_fx[bin][ch][tap] = &(hReverb->loopBufImag_fx[bin][sample]); + + energyBuildup_fx = BASOP_Util_Add_Mant32Exp(energyBuildup_fx, energyBuildup_exp, L_negate(1073741824), 1, &energyBuildup_exp); /* A tap is added, thus remove its energy from the buildup */ + + tap++; + + actualizedEnergy_fx = BASOP_Util_Add_Mant32Exp(actualizedEnergy_fx, actualizedEnergy_exp, 1073741824, 1, &actualizedEnergy_exp); + } + } + + currentEnergy_fx = BASOP_Util_Add_Mant32Exp(currentEnergy_fx, currentEnergy_exp, 0, 0, ¤tEnergy_exp); + currentEnergy_fx = Mpy_32_32(currentEnergy_fx, attenuationFactorPerSampleSq_fx ); + currentEnergy_exp = currentEnergy_exp + attenuationFactorPerSampleSq_exp; + + } + hReverb->taps[bin][ch] = tap; /* Number of taps determined at the above random procedure */ + } + + /* The decorrelator design and IIR attenuation rate affects the energy of reverb, which is compensated here */ + reverb_exp = 0; + hReverb->reverbEqGains_fx[bin] = Sqrt32(revEnes_fx[bin], &reverb_exp); /* Determined reverb spectrum */ + hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp(hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp); + + tmp = BASOP_Util_Divide3232_Scale(intendedEnergy_fx, actualizedEnergy_fx, &tmp_exp); + tmp_exp = tmp_exp + (intendedEnergy_exp - actualizedEnergy_exp); + hReverb->reverbEqGains_fx[bin] = BASOP_Util_Add_Mant32Exp(hReverb->reverbEqGains_fx[bin], reverb_exp, 0, 0, &reverb_exp); + L_tmp = Sqrt32(L_deposit_h(tmp), &tmp_exp); + hReverb->reverbEqGains_fx[bin] = Mpy_32_32(hReverb->reverbEqGains_fx[bin], L_tmp); + reverb_exp = reverb_exp + tmp_exp; + + L_tmp = BASOP_Util_Add_Mant32Exp(1073741824, 1, L_negate(attenuationFactorPerSampleSq_fx), attenuationFactorPerSampleSq_exp, &tmp_exp); + L_tmp = Mpy_32_32(L_tmp, 1073741824); // tmp_exp + 1 + tmp_exp = tmp_exp + 0; + L_tmp = Sqrt32(L_tmp, &tmp_exp); + hReverb->reverbEqGains_fx[bin] = Mpy_32_32(L_tmp, hReverb->reverbEqGains_fx[bin]); + reverb_exp = reverb_exp + tmp_exp; + hReverb->reverbEqGains_fx[bin] = L_shl(hReverb->reverbEqGains_fx[bin], reverb_exp); // making as Q31 + } + return; +} +#endif #ifdef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* @@ -780,7 +981,6 @@ static ivas_error compute_t60_coeffs_fx( pFc_fx = pParams->pFc_fx; targetT60_fx = pParams->pRt60_fx; targetT60_e = pParams->pRt60_e; - Word16 pRt60_e; FOR (bin_idx = 0; bin_idx < tf_T60_len; bin_idx++) { @@ -804,7 +1004,7 @@ static ivas_error compute_t60_coeffs_fx( tmp = BASOP_Util_Cmp_Mant32Exp( L_deposit_h(target_gains_db_fx[bin_idx]), target_gains_db_exp[bin_idx], -2013265920, 7); IF (tmp < 0) { - target_gains_db_fx[bin_idx] = -2013265920; + target_gains_db_fx[bin_idx] = -30720; target_gains_db_exp[bin_idx] = 7; } } @@ -946,7 +1146,7 @@ static void calc_low_shelf_first_order_filter_fx( const Word16 lin_gain_hf ) { Word16 sine_val, shift; - Word16 cos_val, tmp, tan_val, tan_exp, gain_exp, exp, norm_num0, norm_num1, norm_den0, norm_den1, num0, num1, den0, den1; + Word16 cos_val, tmp, tan_val, tan_exp, gain_exp, exp, norm_num0, norm_num1, norm_den0, norm_den1; Word32 L_tmp; tmp = mult( EVS_PI_BY_2_FX, f0 ); @@ -1149,7 +1349,7 @@ static ivas_error calc_jot_t60_coeffs_fx( Word32 L_tmp; Word16 f0_fx, tmp_fx, lf_target_gain_dB_fx, hf_target_gain_dB_fx, mid_crossing_gain_dB_fx; - Word16 lin_gain_lf_fx, lin_gain_hf_fx, shift, expl, exph, addl; + Word16 lin_gain_lf_fx, lin_gain_hf_fx, shift, expl, exph; int16_t f_idx, minidx, e = pH_dB_exp; uint16_t n_points_lf, n_points_hf; @@ -3236,6 +3436,7 @@ ivas_error ivas_reverb_process( * Compute the reverberation - room effect *------------------------------------------------------------------------*/ +#ifndef IVAS_FLOAT_FIXED void ivas_binaural_reverb_processSubframe( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ const int16_t numInChannels, /* i : num inputs to be processed */ @@ -3389,6 +3590,7 @@ void ivas_binaural_reverb_processSubframe( pop_wmops(); return; } +#endif #ifdef IVAS_FLOAT_FIXED /*------------------------------------------------------------------------- @@ -3399,12 +3601,12 @@ void ivas_binaural_reverb_processSubframe( void ivas_binaural_reverb_processSubframe_fx( REVERB_STRUCT_HANDLE hReverb, /* i/o: binaural reverb handle */ - const int16_t numInChannels, /* i : num inputs to be processed */ - const int16_t numSlots, /* i : number of slots to be processed */ + const Word16 numInChannels, /* i : num inputs to be processed */ + const Word16 numSlots, /* i : number of slots to be processed */ Word32 inReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i (Q_in) : input CLDFB data real, Comment: This change swaps two first dimensions as first dimension is not constant. */ Word32 inImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i (Q_in) : input CLDFB data imag */ - Word64 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ - Word64 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ + Word32 outReal[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* o : output CLDFB data real */ + Word32 outImag[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] /* o : output CLDFB data imag */ ) { /* Declare the required variables */ @@ -3439,11 +3641,10 @@ void ivas_binaural_reverb_processSubframe_fx( { /* Add from pre-delay buffer a sample to the loop buffer, in a time-inverted order. * Also apply the spectral gains determined for the reverberation */ - hReverb->loopBufReal_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufReal_fx[bin][invertSampleIndex], - Mpy_32_32( hReverb->preDelayBufferReal_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ) ); - hReverb->loopBufImag_fx[bin][invertSampleIndex] = L_add( hReverb->loopBufImag_fx[bin][invertSampleIndex], - Mpy_32_32( hReverb->preDelayBufferImag_fx[idx][bin], hReverb->reverbEqGains_fx[bin] ) ); - hReverb->preDelayBufferReal_fx[idx][bin] = 0; + Word32 temp_1 = Mpy_32_32(hReverb->preDelayBufferReal_fx[idx][bin], hReverb->reverbEqGains_fx[bin]); + Word32 temp_2 = Mpy_32_32(hReverb->preDelayBufferImag_fx[idx][bin], hReverb->reverbEqGains_fx[bin]); + hReverb->loopBufReal_fx[bin][invertSampleIndex] = L_add(hReverb->loopBufReal_fx[bin][invertSampleIndex], temp_1); + hReverb->loopBufImag_fx[bin][invertSampleIndex] = L_add(hReverb->loopBufImag_fx[bin][invertSampleIndex], temp_2); hReverb->preDelayBufferReal_fx[idx][bin] = 0; hReverb->preDelayBufferImag_fx[idx][bin] = 0; } @@ -3544,8 +3745,8 @@ void ivas_binaural_reverb_processSubframe_fx( FOR( bin = 0; bin < hReverb->numBins; bin++ ) { - outReal[ch][sample][bin] = W_shl( hReverb->outputBufferReal_fx[bin][ch][invertSampleIndex], Q30 ); //Q_in + Q30 - outImag[ch][sample][bin] = W_shl( hReverb->outputBufferImag_fx[bin][ch][invertSampleIndex], Q30 ); //Q_in + Q30 + outReal[ch][sample][bin] = hReverb->outputBufferReal_fx[bin][ch][invertSampleIndex]; // Q_in + Q30 + outImag[ch][sample][bin] = hReverb->outputBufferImag_fx[bin][ch][invertSampleIndex]; // Q_in + Q30 } FOR( ; bin < CLDFB_NO_CHANNELS_MAX; bin++ ) { @@ -3649,7 +3850,7 @@ static ivas_error ivas_binaural_reverb_open( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } set_s( hReverb->tapPhaseShiftType[bin][chIdx], 0, len ); - +#ifndef IVAS_FLOAT_FIXED if ( ( hReverb->tapPointersReal[bin][chIdx] = (float **) malloc( len * sizeof( float * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); @@ -3659,6 +3860,7 @@ static ivas_error ivas_binaural_reverb_open( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural Reverberator\n" ) ); } +#endif #ifdef IVAS_FLOAT_FIXED if ( ( hReverb->tapPointersReal_fx[bin][chIdx] = (Word32 **) malloc( len * sizeof( Word32 * ) ) ) == NULL ) { @@ -3700,7 +3902,27 @@ static ivas_error ivas_binaural_reverb_open( } } +#ifdef IVAS_FLOAT_FIXED + Word32 *revTimes_fx = (Word32 *)malloc(sizeof(Word32) * hReverb->numBins); + Word32 *revEnes_fx = (Word32 *)malloc(sizeof(Word32) * hReverb->numBins); + FOR(int i = 0; i < hReverb->numBins; i++) { + revTimes_fx[i] = (Word32)(revTimes[i] * ONE_IN_Q31); + revEnes_fx[i] = (Word32)(revEnes[i] * ONE_IN_Q31); + } + ivas_binaural_reverb_setReverbTimes_fx( hReverb, sampling_rate, revTimes_fx, revEnes_fx ); + + FOR(Word16 bin = 0; bin < hReverb->numBins; bin++) + { + hReverb->binauralCoherenceDirectGains[bin] = (float)hReverb->binauralCoherenceDirectGains_fx[bin] / ONE_IN_Q31; + hReverb->binauralCoherenceCrossmixGains[bin] = (float)hReverb->binauralCoherenceCrossmixGains_fx[bin] / ONE_IN_Q31; + hReverb->loopAttenuationFactor[bin] = (float)hReverb->loopAttenuationFactor_fx[bin] / ONE_IN_Q31; + hReverb->reverbEqGains[bin] = (float)hReverb->reverbEqGains_fx[bin] / ONE_IN_Q31; + } + free(revTimes_fx); + free(revEnes_fx); +#else ivas_binaural_reverb_setReverbTimes( hReverb, sampling_rate, revTimes, revEnes ); +#endif ivas_binaural_reverb_setPreDelay( hReverb, preDelay ); @@ -3826,10 +4048,13 @@ void ivas_binaural_reverb_close( FOR( chIdx = 0; chIdx < BINAURAL_CHANNELS; chIdx++ ) { free( ( *hReverb )->tapPhaseShiftType[bin][chIdx] ); +#ifndef IVAS_FLOAT_FIXED free( ( *hReverb )->tapPointersReal[bin][chIdx] ); free( ( *hReverb )->tapPointersImag[bin][chIdx] ); +#endif free( ( *hReverb )->outputBufferReal[bin][chIdx] ); free( ( *hReverb )->outputBufferImag[bin][chIdx] ); + #ifdef IVAS_FLOAT_FIXED free( ( *hReverb )->tapPointersReal_fx[bin][chIdx] ); free( ( *hReverb )->tapPointersImag_fx[bin][chIdx] ); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index cc584955c342e08bd9471038c15fdd9a3b8d0d72..f5023902483e4576a16883bc00310705dbd5408e 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -269,6 +269,15 @@ typedef struct dirac_dec_stack_mem float *diffuse_power_factor; #ifdef IVAS_FLOAT_FIXED + /*Prototypes*/ + Word32 *proto_direct_buffer_f_fx; + Word32 *proto_diffuse_buffer_f_fx; + + /*Prototype NRGs*/ + Word32 *proto_power_smooth_fx; + Word32 *proto_power_diff_smooth_fx; + + /*Gain or power factors for directional and diffuse streams*/ Word32 *direct_power_factor_fx; Word32 *diffuse_power_factor_fx; #endif @@ -294,6 +303,7 @@ typedef struct dirac_dec_stack_mem float *onset_filter; #ifdef IVAS_FLOAT_FIXED Word32 *reference_power_fx; + Word16 reference_power_q; Word32 *onset_filter_fx; #endif @@ -385,15 +395,18 @@ typedef struct dirac_output_synthesis_state_structure Word16 direct_power_factor_q; Word16 diffuse_power_factor_q; - Word16 *proto_power_smooth_fx; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + Word32 *proto_power_smooth_fx; /* Smoothed power of the prototype signals. Size: num_freq_bands*num_channels. */ + Word16 proto_power_smooth_q; Word16 *proto_power_smooth_prev_fx; /* Smoothed power of the prototype signals of the previous synthesis block. Size: num_freq_bands*num_channels. */ - Word16 *proto_power_diff_smooth_fx; + Word32 *proto_power_diff_smooth_fx; Word16 *proto_power_diff_smooth_prev_fx; /* only pointer to local buffers */ - Word16 *proto_direct_buffer_f_fx; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ - Word16 *proto_diffuse_buffer_f_fx; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + Word32 *proto_direct_buffer_f_fx; /* Buffer for direct sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + Word16 proto_direct_buffer_f_q; + Word32 *proto_diffuse_buffer_f_fx; /* Buffer for diffuse sound prototype signals. Size: 2*num_freq_bands*num_channels*buffer_length (complex interleaved). */ + Word16 proto_diffuse_buffer_f_q; /* Output gain memories */ Word16 *gains_dir_prev_fx; /* Direct sound gains of current synthesis block. Size: num_freq_bands*num_channel. */ @@ -491,10 +504,14 @@ typedef struct ivas_mcmasa_lfe_synth_struct float targetEneLfeSmooth; float targetEneTransSmooth; #ifdef IVAS_FLOAT_FIXED - Word16 transportEneSmooth_fx; - Word16 protoLfeEneSmooth_fx; - Word16 targetEneLfeSmooth_fx; - Word16 targetEneTransSmooth_fx; + Word32 transportEneSmooth_fx; + Word16 transportEneSmooth_q; + Word32 protoLfeEneSmooth_fx; + Word16 protoLfeEneSmooth_q; + Word32 targetEneLfeSmooth_fx; + Word16 targetEneLfeSmooth_q; + Word32 targetEneTransSmooth_fx; + Word16 targetEneTransSmooth_q; #endif float *lfeSynthRingBuffer; @@ -590,6 +607,7 @@ typedef struct ivas_dirac_rend_data_structure float *proto_frame_dec_f; #ifdef IVAS_FLOAT_FIXED Word16 *proto_frame_f_fx; + Word16 proto_frame_f_q; Word16 *proto_frame_dec_f_fx; #endif @@ -677,8 +695,10 @@ typedef struct ivas_binaural_reverb_struct float *loopBufImag[CLDFB_NO_CHANNELS_MAX]; float preDelayBufferReal[REVERB_PREDELAY_MAX + 1][CLDFB_NO_CHANNELS_MAX]; float preDelayBufferImag[REVERB_PREDELAY_MAX + 1][CLDFB_NO_CHANNELS_MAX]; +#ifndef IVAS_FLOAT_FIXED float **tapPointersReal[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; float **tapPointersImag[CLDFB_NO_CHANNELS_MAX][BINAURAL_CHANNELS]; +#endif float binauralCoherenceCrossmixGains[CLDFB_NO_CHANNELS_MAX]; float binauralCoherenceDirectGains[CLDFB_NO_CHANNELS_MAX];