diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ddb6e07416486374ea3303dec9dc768a7a40299d..86a915bb93e6ae1b41f3f089064a5dc640f37681 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1708,6 +1708,19 @@ void synchro_synthesis_fx( // ivas_dirac_output_synthesis_cov void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( +#ifdef FIX_835_PARAMMC_BUFFER_VALUES + Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ + Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ + Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part */ + Word16 ImagBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ + Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ + Word16 *cx_e, /* i : exponent for accumulated input covariance (real part) */ + Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ + Word16 *cx_imag_e, /* i : exponent accumulated input covariance (imag part) */ + PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ + const Word16 param_band, /* i : parameter band */ + const Word16 nchan_in /* i : number of input channels */ +#else Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part */ @@ -1718,6 +1731,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( Word16 *cx_imag_e, /* i : exponent accumulated input covariance (imag part) */ PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ const Word16 nchan_in /* i : number of input channels */ +#endif ); void configureFdCngDec_ivas_fx( diff --git a/lib_com/options.h b/lib_com/options.h index ff2a6f5fed4f6c12e473191f0f3b73f079f32950..7079776b07e3ec67dd79e380918256e57f9004aa 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -170,6 +170,7 @@ #define FIX_854_HILBERT_SCALING /* VA: reduce lost of precision due to unnecessary scaling, reduce a lot the 2 kHz tone */ #define FIX_856_EXTRACT_L /* VA: Fix undesirable wrap-around */ +#define FIX_835_PARAMMC_BUFFER_VALUES /* FhG: issue 835: wide range of buffer values for cx in ParamMC */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 8a98ef95a862ba3bb3275b8911cb400cac7ef118..9db6d23d3199a015c7640f1063919a072867d779 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -732,7 +732,120 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( * * collect the multi channel input covariance for one filter bank time slot *-------------------------------------------------------------------*/ +#ifdef FIX_835_PARAMMC_BUFFER_VALUES +void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( + Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ + Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ + Word32 *ImagBuffer_fx, /* i : input channel filter bank samples (imaginary part */ + Word16 ImagBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ + Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (real part) */ + Word16 *cx_e, /* i : exponent for accumulated input covariance (real part) */ + Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* o : accumulated input covariance (imaginary part) */ + Word16 *cx_imag_e, /* i : exponent accumulated input covariance (imag part) */ + PARAM_MC_DEC_HANDLE hParamMC, /* i : handle to Parametric MC state */ + const Word16 param_band, /* i : parameter band */ + const Word16 nchan_in /* i : number of input channels */ +) +{ + Word16 cx_init_e[PARAM_MC_MAX_PARAMETER_BANDS]; + Word16 cx_init_imag_e[PARAM_MC_MAX_PARAMETER_BANDS]; + Word16 band_idx, ch_idx; + Word16 brange[2]; + Word32 real_in_buffer_fx[PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND * MAX_TRANSPORT_CHANNELS]; + Word16 real_in_e; + Word32 imag_in_buffer_fx[PARAM_MC_MAX_BANDS_IN_PARAMETER_BAND * MAX_TRANSPORT_CHANNELS]; + Word16 imag_in_e; + Word32 real_buffer_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 imag_buffer_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word16 output_e; + Word16 i, j, tmp1, tmp2, tmp1_e, tmp2_e, shift_imag, shift_real; + Word32 L_tmp; + Word16 band, num_bands; + + /* estimate input covariance */ + /* Already stack here instead of in the process_subframe */ + + /* collect input frame */ + brange[0] = hParamMC->band_grouping[param_band]; + move16(); + brange[1] = hParamMC->band_grouping[param_band + 1]; + move16(); + num_bands = sub( brange[1], brange[0] ); + + FOR( band_idx = 0; band_idx < num_bands; band_idx++ ) + { + band = add( brange[0], band_idx ); + FOR( ch_idx = 0; ch_idx < nchan_in; ch_idx++ ) + { + real_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = RealBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + move32(); + imag_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = ImagBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; + move32(); + } + } + + real_in_e = RealBuffer_e; + move16(); + imag_in_e = ImagBuffer_e; + move16(); + shift_real = sub( L_norm_arr( real_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( num_bands + 1 ) ); + shift_imag = sub( L_norm_arr( imag_in_buffer_fx, imult1616( num_bands, nchan_in ) ), find_guarded_bits_fx( num_bands + 1 ) ); + + real_in_e = sub( real_in_e, shift_real ); + imag_in_e = sub( imag_in_e, shift_imag ); + + output_e = s_max( real_in_e, imag_in_e ); + + FOR( i = 0; i < num_bands * nchan_in; ++i ) + { + real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); + move32(); + imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); + move32(); + } + + cmplx_matrix_square_fx( real_in_buffer_fx, imag_in_buffer_fx, num_bands, nchan_in, real_buffer_fx, imag_buffer_fx, output_e, &output_e ); + v_add_fixed_me( cx_fx, *cx_e, real_buffer_fx, output_e, cx_fx, &tmp1_e, imult1616( nchan_in, nchan_in ), 1 ); + + v_add_fixed_me( cx_imag_fx, *cx_imag_e, imag_buffer_fx, output_e, cx_imag_fx, &tmp2_e, imult1616( nchan_in, nchan_in ), 1 ); + cx_init_e[0] = tmp1_e; + move16(); + cx_init_imag_e[0] = tmp2_e; + move16(); + + // normalizing both the matrices to a common exponent for a better precision + tmp1 = 0; + move16(); + tmp2 = 0; + move16(); + + FOR( j = 0; j < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; j++ ) + { + L_tmp = BASOP_Util_Add_Mant32Exp( cx_fx[j], cx_init_e[0], 0, 0, &tmp1_e ); + L_tmp = BASOP_Util_Add_Mant32Exp( cx_imag_fx[j], cx_init_imag_e[0], 0, 0, &tmp2_e ); + tmp1 = s_max( tmp1, tmp1_e ); + tmp2 = s_max( tmp2, tmp2_e ); + } + + FOR( j = 0; j < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; j++ ) + { + L_tmp = BASOP_Util_Add_Mant32Exp( cx_fx[j], cx_init_e[0], 0, 0, &tmp1_e ); + cx_fx[j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); + move32(); + L_tmp = BASOP_Util_Add_Mant32Exp( cx_imag_fx[j], cx_init_imag_e[0], 0, 0, &tmp2_e ); + cx_imag_fx[j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); + move32(); + } + + *cx_e = tmp1; + move16(); + *cx_imag_e = tmp2; + move16(); + + return; +} +#else void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( Word32 *RealBuffer_fx, /* i : input channel filter bank samples (real part) */ Word16 RealBuffer_e, /* i : exponent input channel filter bank samples (real part)*/ @@ -855,6 +968,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( return; } #endif +#endif /*-------------------------------------------------------------------* * ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot() diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 96835b219d94f29657782da3630e0cf21edffd2d..4aabeaab8ddb9ccf9a727f2890d4071d715e39a0 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -115,8 +115,14 @@ static void ivas_param_mc_get_mixing_matrices( PARAM_MC_DEC_HANDLE hParamMC, IVA static void ivas_param_mc_get_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */ IVAS_OUTPUT_SETUP *hSynthesisOutputSetup, +#ifdef FIX_835_PARAMMC_BUFFER_VALUES + Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands */ + Word16 Cx_in_e, + const Word16 param_band_idx, +#else Word32 Cx_in_fixed[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands */ Word16 Cx_in_e, +#endif Word32 *mixing_matrix_fx[], Word16 *mixing_matrix_e, Word32 *mixing_matrix_res_fx[], @@ -2936,6 +2942,301 @@ void ivas_param_mc_dec_read_BS( *------------------------------------------------------------------------*/ #ifdef IVAS_FLOAT_FIXED +#ifdef FIX_835_PARAMMC_BUFFER_VALUES +void ivas_param_mc_dec_digest_tc_fx( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ + Word32 *transport_channels_f_fx[], + Word16 transport_f_e ) +{ + PARAM_MC_DEC_HANDLE hParamMC; + Word16 i, ch; + Word16 is_next_band, skip_next_band; + Word16 slot_idx, param_band_idx; + Word16 nchan_transport, nchan_out_transport, nchan_out_cldfb; + Word16 nchan_out_cov; + /*CLDFB*/ + /* format converter */ + Word16 channel_active[MAX_OUTPUT_CHANNELS]; + IVAS_OUTPUT_SETUP *hSynthesisOutputSetup; + + hParamMC = st_ivas->hParamMC; + assert( hParamMC ); + Word32 *pCx, *pCx_imag; + Word32 cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 cx_imag_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 cx_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 cx_imag_next_band_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + + Word16 cx_buff_e[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word16 cx_e; + Word16 cx_imag_e, tmp_e; + Word16 qout = 0; + move16(); + + Word32 real_part_fx, imag_part_fx, L_tmp1, L_tmp2; + + Word16 max_e; + + push_wmops( "param_mc_dec_digest_tc" ); + + set16_fx( channel_active, 0, MAX_CICP_CHANNELS ); + nchan_transport = st_ivas->nchan_transport; + move16(); + nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); + + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) + { + nchan_out_cldfb = BINAURAL_CHANNELS; + move16(); + set16_fx( channel_active, 1, nchan_out_cldfb ); + nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ); + hSynthesisOutputSetup = &st_ivas->hTransSetup; + } + ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) ) + { + nchan_out_cov = nchan_out_transport; + move16(); + nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); + hSynthesisOutputSetup = &st_ivas->hTransSetup; + } + ELSE IF( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) + { + nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ); + nchan_out_cldfb = nchan_out_cov; + move16(); + set16_fx( channel_active, 1, nchan_out_cov ); + hSynthesisOutputSetup = &st_ivas->hOutSetup; + } + ELSE + { + nchan_out_cov = nchan_out_transport; + move16(); + nchan_out_cldfb = nchan_out_transport; + move16(); + set16_fx( channel_active, 1, nchan_out_cov ); + hSynthesisOutputSetup = &st_ivas->hTransSetup; + } + + /* adapt transient position */ + IF( hParamMC->hMetadataPMC->bAttackPresent ) + { + hParamMC->hMetadataPMC->attackIndex = s_max( 0, add( hParamMC->hMetadataPMC->attackIndex, shr( sub( nCldfbSlots, DEFAULT_JBM_CLDFB_TIMESLOTS ), 1 ) ) ); + move16(); + } + /* adapt subframes */ + hParamMC->num_slots = nCldfbSlots; + move16(); + hParamMC->slots_rendered = 0; + move16(); + hParamMC->subframes_rendered = 0; + move16(); + ivas_jbm_dec_get_adapted_subframes( nCldfbSlots, hParamMC->subframe_nbslots, &hParamMC->nb_subframes ); + st_ivas->hTcBuffer->nb_subframes = hParamMC->nb_subframes; + move16(); + Copy( hParamMC->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hParamMC->nb_subframes ); + + ivas_param_mc_dec_compute_interpolator_fx( hParamMC->hMetadataPMC->bAttackPresent, hParamMC->hMetadataPMC->attackIndex, nCldfbSlots, hParamMC->h_output_synthesis_params.interpolator_fx ); + + /* loop over two bands at a time */ + FOR( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 ) + { + /* don't process next band if it exceeds the limit */ + skip_next_band = ( ( param_band_idx + 1 ) == hParamMC->num_param_bands_synth ) ? 1 : 0; + + set_zero_fx( cx_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); + set_zero_fx( cx_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); + set_zero_fx( cx_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); + set_zero_fx( cx_imag_next_band_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); + + cx_e = 0; + move16(); + cx_imag_e = 0; + move16(); + // cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; + move16(); + + /* slot loop for gathering the input data */ + FOR( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) + { + IF( st_ivas->hDecoderConfig->Opt_tsm ) + { + IF( param_band_idx == 0 ) /* only run cldfbAna once */ + { + Word32 RealBuffer_fx[CLDFB_NO_CHANNELS_MAX]; + Word32 ImagBuffer_fx[CLDFB_NO_CHANNELS_MAX]; + + /* CLDFB Analysis*/ + FOR( ch = 0; ch < nchan_transport; ch++ ) + { + qout = transport_f_e; + move16(); + cldfbAnalysis_ts_fx_fixed_q( &( transport_channels_f_fx[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer_fx, ImagBuffer_fx, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch], &qout ); + + Copy32( RealBuffer_fx, &hParamMC->Cldfb_RealBuffer_tc_fx[L_add( L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport ), L_mult0( ch, hParamMC->num_freq_bands ) )], hParamMC->num_freq_bands ); + Copy32( ImagBuffer_fx, &hParamMC->Cldfb_ImagBuffer_tc_fx[L_add( L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport ), L_mult0( ch, hParamMC->num_freq_bands ) )], hParamMC->num_freq_bands ); + } + + hParamMC->Cldfb_ImagBuffer_tc_e = qout; + move16(); + } + } + IF( GE_16( slot_idx, shl( hParamMC->hMetadataPMC->attackIndex, 1 ) ) ) + { + FOR( is_next_band = 0; is_next_band < 2; is_next_band++ ) + { + test(); + IF( is_next_band && skip_next_band ) + { + continue; + } + IF( is_next_band ) + { + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6, + &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6, + cx_next_band_fx, + &cx_e, + cx_imag_next_band_fx, + &cx_imag_e, + hParamMC, + add( param_band_idx, is_next_band ), + nchan_transport ); + } + ELSE + { + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( &hParamMC->Cldfb_RealBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + /*hParamMC->Cldfb_RealBuffer_tc_e*/ Q31 - Q6, + &hParamMC->Cldfb_ImagBuffer_tc_fx[L_mult0( imult1616( slot_idx, hParamMC->num_freq_bands ), nchan_transport )], + /*hParamMC->Cldfb_ImagBuffer_tc_e*/ Q31 - Q6, + cx_fx, + &cx_e, + cx_imag_fx, + &cx_imag_e, + hParamMC, + add( param_band_idx, is_next_band ), + nchan_transport ); + } + } + } + } + + /* map from complex input covariance to real values */ + FOR( is_next_band = 0; is_next_band < 2; is_next_band++ ) + { + test(); + IF( is_next_band && skip_next_band ) + { + continue; + } + /* Cx for transport channels */ + IF( is_next_band ) + { + pCx = &cx_next_band_fx[0]; + pCx_imag = &cx_imag_next_band_fx[0]; + } + ELSE + { + pCx = &cx_fx[0]; + pCx_imag = &cx_imag_fx[0]; + } + + FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ ) + { + real_part_fx = pCx[i]; + imag_part_fx = pCx_imag[i]; + move32(); + move32(); + cx_buff_e[i] = cx_e; + move16(); + /* (a-ib)(c+id) = ac + bd + i(ad-bc) */ + IF( LT_16( param_band_idx, hParamMC->max_param_band_abs_cov ) ) + { + L_tmp1 = Mpy_32_32( real_part_fx, real_part_fx ); + L_tmp2 = Mpy_32_32( imag_part_fx, imag_part_fx ); + L_tmp1 = BASOP_Util_Add_Mant32Exp( L_tmp1, add( cx_e, cx_e ), L_tmp2, add( cx_imag_e, cx_imag_e ), &tmp_e ); + pCx[i] = Sqrt32( L_tmp1, &tmp_e ); + cx_fx[i] = Sqrt32( L_tmp1, &tmp_e ); + move32(); + cx_buff_e[i] = tmp_e; + move16(); + } + ELSE + { + pCx[i] = real_part_fx; + move32(); + cx_buff_e[i] = cx_e; + move16(); + } + } + } + + max_e = cx_buff_e[0]; + move16(); + + /* Cx for transport channels */ + FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ ) + { + + IF( LT_16( max_e, cx_buff_e[i] ) ) + { + max_e = cx_buff_e[i]; + } + } + + /* Cx for transport channels */ + FOR( i = 0; i < imult1616( nchan_transport, nchan_transport ); i++ ) + { + + cx_fx[i] = L_shr( cx_fx[i], sub( max_e, cx_buff_e[i] ) ); + move32(); + } + + cx_e = max_e; + move16(); + + + /* we have to do it similar to the encoder in case of attacks (i.e. accumulate two bands) to ensure correct DMX of the target covariance*/ + + test(); + test(); + IF( hParamMC->hMetadataPMC->bAttackPresent && ( EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) ) + { + v_add_fx( cx_fx, cx_next_band_fx, cx_fx, imult1616( nchan_transport, nchan_transport ) ); + Copy32( cx_fx, cx_next_band_fx, imult1616( nchan_transport, nchan_transport ) ); + } + + FOR( is_next_band = 0; is_next_band < 2; is_next_band++ ) + { + test(); + IF( is_next_band && skip_next_band ) + { + continue; + } + + IF( NE_32( hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) ) + { + IF( is_next_band ) + { + + ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_next_band_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov ); + } + ELSE + { + + ivas_param_mc_get_mixing_matrices_fx( hParamMC, hSynthesisOutputSetup, cx_fx, cx_e, add( param_band_idx, is_next_band ), hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp, nchan_out_transport, hParamMC->synthesis_conf, nchan_transport, nchan_out_cov ); + } + } + } + } + pop_wmops(); + + return; +} +#else void ivas_param_mc_dec_digest_tc_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ const uint8_t nCldfbSlots, /* i : number of CLFBS slots in the transport channels */ @@ -3169,6 +3470,7 @@ void ivas_param_mc_dec_digest_tc_fx( return; } +#endif #else void ivas_param_mc_dec_digest_tc( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ @@ -5003,6 +5305,398 @@ static void ivas_param_mc_get_mixing_matrices( return; } #else +#ifdef FIX_835_PARAMMC_BUFFER_VALUES +static void ivas_param_mc_get_mixing_matrices_fx( + PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */ + IVAS_OUTPUT_SETUP *hSynthesisOutputSetup, + Word32 Cx_in_fixed[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : input covariance for all parameter bands */ + Word16 Cx_in_e, + const Word16 param_band_idx, /* i : parameter band index */ + Word32 *mixing_matrix_fx[], + Word16 *mixing_matrix_e, + Word32 *mixing_matrix_res_fx[], + Word16 *mixing_matrix_res_e, + const Word16 nY_intern, /* i : number of channels in the transported format */ + const PARAM_MC_SYNTHESIS_CONF synth_config, /* i : Parametric MC synthesis config */ + const Word16 nX, /* i : number of transport channels */ + const Word16 nY_cov /* i : number of covariance synthesis output channels */ +) +{ + Word16 matSize = MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS; + Word16 nY_band; + Word16 num_lfe_bands; + Word16 brange[2]; + uint16_t i; + Word16 ch_idx1, ch_idx2, lfe_idx1, lfe_idx2; + Word16 remove_lfe; + Word16 lfe_indices[PARAM_MC_LOCAL_SZ_LFE_MAP]; + + Word32 Cx_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word32 Cy_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + + Word32 Cy_full_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + + Word32 Cr_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word16 Cr_e; + Word32 Cy_diag_fx[MAX_OUTPUT_CHANNELS]; + Word16 Cy_diag_buff_e[MAX_OUTPUT_CHANNELS]; + Word32 mixing_matrix_local_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + Word16 Cy_diag_e = 0, mixing_matrix_local_e = 0; + Word32 Cproto_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word16 Cproto_e; + Word32 *proto_matrix_ptr_fx; + Word32 *Cx_state_fx; + Word32 *Cx_old_state_fx; + Word32 Cy_state_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word32 *Cy_old_state_fx; + Word16 Cx_state_e; + Word16 Cy_state_e; + Word32 mixing_matrix_res_local_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + Word16 mixing_matrix_res_local_e; + Word32 L_tmp; + Word16 tmp_e, tmp; + + Word16 proto_matrix_e = hParamMC->h_output_synthesis_params.proto_matrix_e; + move16(); + Word32 proto_matrix_noLFE_fx[PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS]; + + Word32 mat_mult_buffer1_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + + Word32 Cproto_diag_fx[MAX_CICP_CHANNELS]; + Word16 mat_mult_buffer1_e, proto_matrix_ptr_e, Cproto_diag_e; + + Word32 *ptrMM_fx; + Word32 *ptrMM_out_fx; + + Word16 Cy_e, Cx_e; + Word16 Cy_full_e; + + set_zero_fx( Cproto_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + set_zero_fx( mat_mult_buffer1_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS ); +#ifdef MSAN_FIX + set_zero_fx( mixing_matrix_res_local_fx, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); +#endif + Word16 proto_matrix_noLFE_e = 0; + move16(); + + Word32 Cx_in_fx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; + + Copy32( Cx_in_fixed, Cx_in_fx, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); + + nY_band = nY_cov; + move16(); + num_lfe_bands = 0; + move16(); + remove_lfe = 0; + move16(); + + set16_fx( lfe_indices, -1, PARAM_MC_LOCAL_SZ_LFE_MAP ); + IF( hSynthesisOutputSetup->num_lfe ) + { + Word32 *proto_matrix_ptr_in_fx; + FOR( lfe_idx1 = 0; lfe_idx1 < hSynthesisOutputSetup->num_lfe; lfe_idx1++ ) + { + lfe_indices[lfe_idx1 + 1] = hSynthesisOutputSetup->index_lfe[lfe_idx1]; + move16(); + } + lfe_indices[add( hSynthesisOutputSetup->num_lfe, 1 )] = nY_cov; + move16(); + proto_matrix_ptr_fx = &proto_matrix_noLFE_fx[0]; + proto_matrix_ptr_in_fx = &hParamMC->h_output_synthesis_params.proto_matrix_fx[0]; + proto_matrix_noLFE_e = proto_matrix_e; + move16(); + + set_zero_fx( proto_matrix_noLFE_fx, PARAM_MC_MAX_TRANSPORT_CHANS * MAX_CICP_CHANNELS ); + + FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) + { + FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + { + FOR( ch_idx2 = add( lfe_indices[lfe_idx1], 1 ); ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) + { + *( proto_matrix_ptr_fx++ ) = *( proto_matrix_ptr_in_fx++ ); + move32(); + } + proto_matrix_ptr_in_fx++; + } + proto_matrix_ptr_in_fx--; + } + + proto_matrix_ptr_e = proto_matrix_e; + move16(); + } + + if ( hParamMC->hMetadataPMC->lfe_on ) + { + num_lfe_bands = PARAM_MC_MAX_BAND_LFE; + move16(); + } + IF( hSynthesisOutputSetup->num_lfe > 0 && param_band_idx >= num_lfe_bands ) + { + remove_lfe = 1; + move16(); + nY_band = sub( nY_cov, hSynthesisOutputSetup->num_lfe ); + proto_matrix_ptr_fx = proto_matrix_noLFE_fx; + proto_matrix_ptr_e = proto_matrix_noLFE_e; + move16(); + } + ELSE + { + proto_matrix_ptr_fx = hParamMC->h_output_synthesis_params.proto_matrix_fx; + proto_matrix_ptr_e = hParamMC->h_output_synthesis_params.proto_matrix_e; + move16(); + } + + brange[0] = hParamMC->band_grouping[param_band_idx]; + move16(); + brange[1] = hParamMC->band_grouping[param_band_idx + 1]; + move16(); + + Cx_state_fx = Cx_in_fx; + Cx_old_state_fx = hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx]; + Cy_old_state_fx = hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx]; + + + /* Getting mixing mtx */ + /* estimate target cov from input cov and proto_matrix */ + + Cx_state_e = Cx_in_e; + move16(); + matrix_product_fx( hParamMC->proto_matrix_int_fx, nY_intern, nX, 0, Cx_state_fx, nX, nX, 0, mat_mult_buffer1_fx ); + mat_mult_buffer1_e = add( hParamMC->proto_matrix_int_e, Cx_in_e ); + + matrix_product_fx( mat_mult_buffer1_fx, nY_intern, nX, 0, hParamMC->proto_matrix_int_fx, nY_intern, nX, 1, Cproto_fx ); + Cproto_e = add( mat_mult_buffer1_e, hParamMC->proto_matrix_int_e ); + + FOR( ch_idx1 = 0; ch_idx1 < nY_intern; ch_idx1++ ) + { + IF( BASOP_Util_Cmp_Mant32Exp( Cproto_fx[L_add( ch_idx1, L_mult0( ch_idx1, nY_intern ) )], Cproto_e, 0, 0 ) < 0 ) + { + Cproto_fx[L_add( ch_idx1, L_mult0( ch_idx1, nY_intern ) )] = 0; + move32(); + } + } + + set_zero_fx( Cy_state_fx, matSize ); + Cy_state_e = 0; + move16(); + + ivas_param_mc_dequantize_cov_fx( hParamMC, + hParamMC->icld_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe ), + hParamMC->icc_q_fx + L_mult0( param_band_idx, hParamMC->hMetadataPMC->icc_mapping_conf->icc_map_size_lfe ), + param_band_idx, nY_cov, + synth_config, + nY_intern, + nX, Cx_state_fx, Cx_state_e, Cproto_fx, Cproto_e, Cy_state_fx, &Cy_state_e ); + + // dbgwrite2_txt(Cy_state_fx,nY_intern*nY_intern,"../cy_state_fx.txt"); + + /* Smoothing: Sum over two buffers */ + IF( hParamMC->hMetadataPMC->bAttackPresent ) + { + /* no smoothing on attacks */ + Copy32( Cx_state_fx, Cx_fx, imult1616( nX, nX ) ); + Copy32( Cy_state_fx, Cy_full_fx, imult1616( nY_cov, nY_cov ) ); + Cy_full_e = Cy_state_e; + move16(); + Cx_e = Cx_state_e; + move16(); + } + ELSE + { + /* smoothing gains are now identical to one, simply add up */ + // v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov ); + + v_add_fixed_me( Cx_state_fx, Cx_state_e, Cx_old_state_fx, hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], Cx_fx, &Cx_e, imult1616( nX, nX ), 1 ); + v_add_fixed_me( Cy_state_fx, Cy_state_e, Cy_old_state_fx, hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], Cy_full_fx, &Cy_full_e, imult1616( nY_cov, nY_cov ), 1 ); + } + + Copy32( Cx_state_fx, Cx_old_state_fx, imult1616( nX, nX ) ); + + Copy32( Cy_state_fx, Cy_old_state_fx, imult1616( nY_cov, nY_cov ) ); + + Word16 new_e = 0; + move16(); + + hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = Cx_state_e; + move16(); + hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = Cy_state_e; + move16(); + + FOR( i = 0; i < imult1616( nX, nX ); i++ ) + { + if ( Cx_old_state_fx[i] != 0 ) + { + new_e = hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx]; + move16(); + } + } + + hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = new_e; + move16(); + + new_e = 0; + move16(); + + FOR( i = 0; i < imult1616( nY_cov, nY_cov ); i++ ) + { + if ( Cy_old_state_fx[i] != 0 ) + { + new_e = hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx]; + move16(); + } + } + + hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = new_e; + move16(); + + /* remove LFE IF necessary */ + IF( remove_lfe ) + { + + Cy_e = Cy_full_e; + remove_lfe_from_cy_fx( nY_cov, lfe_indices, hSynthesisOutputSetup->num_lfe, Cy_full_fx, Cy_fx ); + } + ELSE + { + Copy32( Cy_full_fx, Cy_fx, imult1616( nY_band, nY_band ) ); + Cy_e = Cy_full_e; + move16(); + } + + matrix_product_fx( proto_matrix_ptr_fx, nY_band, nX, 0, Cx_fx, nX, nX, 0, mat_mult_buffer1_fx ); + mat_mult_buffer1_e = add( proto_matrix_ptr_e, Cx_e ); + + matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, nY_band, nX, 0, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 1, Cproto_diag_fx, &Cproto_diag_e ); + + /* make sure we have no negative entries in Cproto_diag due to rounding errors */ + + FOR( ch_idx1 = 0; ch_idx1 < nY_band; ch_idx1++ ) + { + if ( BASOP_Util_Cmp_Mant32Exp( Cproto_diag_fx[ch_idx1], Cproto_diag_e, 0, 0 ) < 0 ) + { + Cproto_diag_fx[ch_idx1] = 0; + move16(); + } + } + + + /* Computing the mixing matrices */ + + /* bands with decorr */ + IF( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) ) + { + computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 0, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e ); + /* Compute mixing matrix FOR residual */ + computeMixingMatricesResidual_fx( nY_band, Cproto_diag_fx, Cproto_diag_e, Cr_fx, Cr_e, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_res_local_fx, &mixing_matrix_res_local_e ); + + IF( remove_lfe ) + { + set_zero_fx( mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) ); + + ptrMM_fx = mixing_matrix_res_local_fx; + ptrMM_out_fx = mixing_matrix_res_fx[param_band_idx]; + FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + { + FOR( ch_idx1 = add( lfe_indices[lfe_idx1], 1 ); ch_idx1 < lfe_indices[lfe_idx1 + 1]; ch_idx1++ ) + { + FOR( lfe_idx2 = 0; lfe_idx2 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx2++ ) + { + FOR( ch_idx2 = add( lfe_indices[lfe_idx2], 1 ); ch_idx2 < lfe_indices[lfe_idx2 + 1]; ch_idx2++ ) + { + *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); + move32(); + } + ptrMM_out_fx++; + } + ptrMM_out_fx--; + } + ptrMM_out_fx += nY_cov; + } + mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e; + move16(); + } + ELSE + { + Copy32( mixing_matrix_res_local_fx, mixing_matrix_res_fx[param_band_idx], imult1616( nY_cov, nY_cov ) ); + mixing_matrix_res_e[param_band_idx] = mixing_matrix_res_local_e; + move16(); + } + } + ELSE IF( brange[0] < hParamMC->max_band_energy_compensation ) + { + /* Compute mixing matrices (energy compensation only) */ + computeMixingMatrices_fx( nX, nY_band, Cx_fx, Cx_e, Cy_fx, Cy_e, proto_matrix_ptr_fx, proto_matrix_ptr_e, 1, PARAM_MC_REG_SX_FX, 0, PARAM_MC_REG_GHAT_FX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e, Cr_fx, &Cr_e ); + } + ELSE + { + /*IF neither decorrelation nor energy compensation is applied*/ + FOR( i = 0; i < nY_band; i++ ) + { + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i], L_add( Cproto_diag_fx[i], EPSILON_FX ), &tmp_e ); + tmp_e = add( Cy_diag_e, Cproto_diag_e ); + L_tmp = Sqrt32( L_deposit_h( tmp ), &tmp_e ); + Cy_diag_fx[i] = L_tmp; + move32(); + Cy_diag_buff_e[i] = tmp_e; + move16(); + } + + + Cy_diag_e = Cy_diag_buff_e[0]; + move16(); + + FOR( i = 1; i < nY_band; i++ ) + { + if ( LT_16( Cy_diag_e, Cy_diag_buff_e[i] ) ) + { + Cy_diag_e = Cy_diag_buff_e[i]; + move16(); + } + } + + FOR( i = 0; i < nY_band; i++ ) + { + Cy_diag_fx[i] = L_shr( Cy_diag_fx[i], sub( Cy_diag_e, Cy_diag_buff_e[i] ) ); + move32(); + } + + diag_matrix_product_fx( Cy_diag_fx, Cy_diag_e, nY_band, proto_matrix_ptr_fx, proto_matrix_ptr_e, nY_band, nX, 0, mixing_matrix_local_fx, &mixing_matrix_local_e ); + } + + IF( remove_lfe ) + { + set_zero_fx( mixing_matrix_fx[param_band_idx], imult1616( nX, nY_cov ) ); + ptrMM_fx = mixing_matrix_local_fx; + ptrMM_out_fx = mixing_matrix_fx[param_band_idx]; + FOR( ch_idx1 = 0; ch_idx1 < nX; ch_idx1++ ) + { + FOR( lfe_idx1 = 0; lfe_idx1 < add( hSynthesisOutputSetup->num_lfe, 1 ); lfe_idx1++ ) + { + FOR( ch_idx2 = add( lfe_indices[lfe_idx1], 1 ); ch_idx2 < lfe_indices[lfe_idx1 + 1]; ch_idx2++ ) + { + *( ptrMM_out_fx++ ) = *( ptrMM_fx++ ); + move32(); + } + ptrMM_out_fx++; + } + ptrMM_out_fx--; + } + + mixing_matrix_e[param_band_idx] = mixing_matrix_local_e; + move16(); + } + ELSE + { + Copy32( mixing_matrix_local_fx, mixing_matrix_fx[param_band_idx], imult1616( nY_cov, nX ) ); + mixing_matrix_e[param_band_idx] = mixing_matrix_local_e; + move16(); + } + + return; +} +#else static void ivas_param_mc_get_mixing_matrices_fx( PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */ IVAS_OUTPUT_SETUP *hSynthesisOutputSetup, @@ -5400,6 +6094,7 @@ static void ivas_param_mc_get_mixing_matrices_fx( return; } #endif +#endif /*-------------------------------------------------------------------------