From 5a431bcb2f11901f8207fdb208d7ccd4254f2b92 Mon Sep 17 00:00:00 2001 From: malenov Date: Mon, 4 Nov 2024 14:04:45 +0100 Subject: [PATCH 1/2] fix instrumentation issues --- lib_dec/ivas_mc_param_dec.c | 247 ++++++++++++++++++++++++++---------- 1 file changed, 179 insertions(+), 68 deletions(-) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index a365c6ed3..30927bfaf 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -1505,23 +1505,14 @@ void ivas_param_mc_dec_digest_tc( set_zero( cx_imag, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); set_zero( cx_next_band, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); set_zero( cx_imag_next_band, PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); -#else - for ( param_band_idx = 0; param_band_idx < PARAM_MC_MAX_PARAMETER_BANDS; param_band_idx++ ) - { - set_zero( cx[param_band_idx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - set_zero( cx_imag[param_band_idx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); - } -#endif /* slot loop for gathering the input data */ for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) { if ( st_ivas->hDecoderConfig->Opt_tsm ) { -#ifdef FIX_835_PARAMMC_BUFFER_VALUES if ( param_band_idx == 0 ) /* only run cldfbAna once */ { -#endif float RealBuffer[CLDFB_NO_CHANNELS_MAX]; float ImagBuffer[CLDFB_NO_CHANNELS_MAX]; @@ -1533,81 +1524,53 @@ void ivas_param_mc_dec_digest_tc( mvr2r( RealBuffer, &hParamMC->Cldfb_RealBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); mvr2r( ImagBuffer, &hParamMC->Cldfb_ImagBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); } -#ifdef FIX_835_PARAMMC_BUFFER_VALUES } -#endif } + if ( slot_idx >= 2 * hParamMC->hMetadataPMC->attackIndex ) { -#ifdef FIX_835_PARAMMC_BUFFER_VALUES for ( is_next_band = 0; is_next_band < 2; is_next_band++ ) { if ( is_next_band && skip_next_band ) { continue; } -#endif + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( &hParamMC->Cldfb_RealBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport], &hParamMC->Cldfb_ImagBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport], -#ifdef FIX_835_PARAMMC_BUFFER_VALUES is_next_band ? cx_next_band : cx, is_next_band ? cx_imag_next_band : cx_imag, param_band_idx + is_next_band, -#else - cx, - cx_imag, -#endif hParamMC, nchan_transport ); -#ifdef FIX_835_PARAMMC_BUFFER_VALUES } -#endif } } /* map from complex input covariance to real values */ -#ifdef FIX_835_PARAMMC_BUFFER_VALUES for ( is_next_band = 0; is_next_band < 2; is_next_band++ ) { if ( is_next_band && skip_next_band ) { continue; } -#else - for ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) - { -#endif + /* Cx for transport channels */ -#ifdef FIX_835_PARAMMC_BUFFER_VALUES pCx = is_next_band ? &cx_next_band[0] : &cx[0]; pCx_imag = is_next_band ? &cx_imag_next_band[0] : &cx_imag[0]; -#endif for ( i = 0; i < nchan_transport * nchan_transport; i++ ) { -#ifdef FIX_835_PARAMMC_BUFFER_VALUES real_part = pCx[i]; imag_part = pCx_imag[i]; -#else - real_part = cx[param_band_idx][i]; - imag_part = cx_imag[param_band_idx][i]; -#endif /* (a-ib)(c+id) = ac + bd + i(ad-bc) */ if ( param_band_idx < hParamMC->max_param_band_abs_cov ) { -#ifdef FIX_835_PARAMMC_BUFFER_VALUES pCx[i] = sqrtf( real_part * real_part + imag_part * imag_part ); -#else - cx[param_band_idx][i] = sqrtf( real_part * real_part + imag_part * imag_part ); -#endif } else { -#ifdef FIX_835_PARAMMC_BUFFER_VALUES pCx[i] = real_part; -#else - cx[param_band_idx][i] = real_part; -#endif } } } @@ -1615,37 +1578,23 @@ void ivas_param_mc_dec_digest_tc( /* 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*/ if ( hParamMC->hMetadataPMC->bAttackPresent && ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) ) { -#ifdef FIX_835_PARAMMC_BUFFER_VALUES v_add( cx, cx_next_band, cx, nchan_transport * nchan_transport ); mvr2r( cx, cx_next_band, nchan_transport * nchan_transport ); -#else - for ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 ) - { - v_add( cx[param_band_idx], cx[param_band_idx + 1], cx[param_band_idx], nchan_transport * nchan_transport ); - mvr2r( cx[param_band_idx], cx[param_band_idx + 1], nchan_transport * nchan_transport ); - } -#endif } -#ifdef FIX_835_PARAMMC_BUFFER_VALUES for ( is_next_band = 0; is_next_band < 2; is_next_band++ ) { if ( is_next_band && skip_next_band ) { continue; } -#endif if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) { ivas_param_mc_get_mono_stereo_mixing_matrices( hParamMC, -#ifdef FIX_835_PARAMMC_BUFFER_VALUES is_next_band ? cx_next_band : cx, param_band_idx + is_next_band, -#else - cx, -#endif hParamMC->h_output_synthesis_cov_state.mixing_matrix, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res, nchan_out_transport, @@ -1657,12 +1606,8 @@ void ivas_param_mc_dec_digest_tc( /* generate mixing matrices */ ivas_param_mc_get_mixing_matrices( hParamMC, hSynthesisOutputSetup, -#ifdef FIX_835_PARAMMC_BUFFER_VALUES is_next_band ? cx_next_band : cx, param_band_idx + is_next_band, -#else - cx, -#endif hParamMC->h_output_synthesis_cov_state.mixing_matrix, hParamMC->h_output_synthesis_cov_state.mixing_matrix_res, nchan_out_transport, @@ -1670,9 +1615,99 @@ void ivas_param_mc_dec_digest_tc( nchan_transport, nchan_out_cov ); } -#ifdef FIX_835_PARAMMC_BUFFER_VALUES } } + +#else + for ( param_band_idx = 0; param_band_idx < PARAM_MC_MAX_PARAMETER_BANDS; param_band_idx++ ) + { + set_zero( cx[param_band_idx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); + set_zero( cx_imag[param_band_idx], PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS ); + } + + /* slot loop for gathering the input data */ + for ( slot_idx = 0; slot_idx < nCldfbSlots; slot_idx++ ) + { + if ( st_ivas->hDecoderConfig->Opt_tsm ) + { + float RealBuffer[CLDFB_NO_CHANNELS_MAX]; + float ImagBuffer[CLDFB_NO_CHANNELS_MAX]; + + /* CLDFB Analysis*/ + for ( ch = 0; ch < nchan_transport; ch++ ) + { + cldfbAnalysis_ts( &( transport_channels_f[ch][hParamMC->num_freq_bands * slot_idx] ), RealBuffer, ImagBuffer, hParamMC->num_freq_bands, st_ivas->cldfbAnaDec[ch] ); + + mvr2r( RealBuffer, &hParamMC->Cldfb_RealBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); + mvr2r( ImagBuffer, &hParamMC->Cldfb_ImagBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport + ch * hParamMC->num_freq_bands], hParamMC->num_freq_bands ); + } + } + + if ( slot_idx >= 2 * hParamMC->hMetadataPMC->attackIndex ) + { + ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot( &hParamMC->Cldfb_RealBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport], + &hParamMC->Cldfb_ImagBuffer_tc[slot_idx * hParamMC->num_freq_bands * nchan_transport], + cx, + cx_imag, + hParamMC, + nchan_transport ); + } + } + + /* map from complex input covariance to real values */ + for ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) + { + /* Cx for transport channels */ + for ( i = 0; i < nchan_transport * nchan_transport; i++ ) + { + real_part = cx[param_band_idx][i]; + imag_part = cx_imag[param_band_idx][i]; + + /* (a-ib)(c+id) = ac + bd + i(ad-bc) */ + if ( param_band_idx < hParamMC->max_param_band_abs_cov ) + { + cx[param_band_idx][i] = sqrtf( real_part * real_part + imag_part * imag_part ); + } + else + { + cx[param_band_idx][i] = real_part; + } + } + } + + /* 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*/ + if ( hParamMC->hMetadataPMC->bAttackPresent && ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_LS_CONV_COV || hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) ) + { + for ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx += 2 ) + { + v_add( cx[param_band_idx], cx[param_band_idx + 1], cx[param_band_idx], nchan_transport * nchan_transport ); + mvr2r( cx[param_band_idx], cx[param_band_idx + 1], nchan_transport * nchan_transport ); + } + } + + if ( hParamMC->synthesis_conf == PARAM_MC_SYNTH_MONO_STEREO ) + { + ivas_param_mc_get_mono_stereo_mixing_matrices( hParamMC, + cx, + hParamMC->h_output_synthesis_cov_state.mixing_matrix, + hParamMC->h_output_synthesis_cov_state.mixing_matrix_res, + nchan_out_transport, + nchan_transport, + nchan_out_cov ); + } + else + { + /* generate mixing matrices */ + ivas_param_mc_get_mixing_matrices( hParamMC, + hSynthesisOutputSetup, + cx, + hParamMC->h_output_synthesis_cov_state.mixing_matrix, + hParamMC->h_output_synthesis_cov_state.mixing_matrix_res, + nchan_out_transport, + hParamMC->synthesis_conf, + nchan_transport, + nchan_out_cov ); + } #endif pop_wmops(); @@ -2648,7 +2683,7 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( float *mixing_matrix_res[], /* o : residual mixing matrices for all parameter bands */ const int16_t nY_intern, /* i : number of channels of the transport format */ const int16_t nX, /* i : number of transport channels */ - const int16_t nY_cov ) /* i : number of output channels */ + const int16_t nY_cov /* i : number of output channels */ #else PARAM_MC_DEC_HANDLE hParamMC, /* i : Parametric MC handle */ float Cx_in[PARAM_MC_MAX_PARAMETER_BANDS][PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS], /* i : transport channel covariance for all parameter bands */ @@ -2656,8 +2691,9 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( float *mixing_matrix_res[], /* o : residual mixing matrices for all parameter bands */ const int16_t nY_intern, /* i : number of channels of the transport format */ const int16_t nX, /* i : number of transport channels */ - const int16_t nY_cov ) /* i : number of output channels */ + const int16_t nY_cov /* i : number of output channels */ #endif +) { #ifndef FIX_835_PARAMMC_BUFFER_VALUES int16_t param_band_idx; @@ -2685,7 +2721,6 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( #ifndef FIX_835_PARAMMC_BUFFER_VALUES for ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { -#endif float Cy_full[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; float mixing_matrix_woLFE[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; float Nrqq[MAX_OUTPUT_CHANNELS]; @@ -2693,13 +2728,10 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( int16_t k, l; float *ild_q; -#ifdef FIX_835_PARAMMC_BUFFER_VALUES - Cx_state = Cx_in; -#else - Cx_state = Cx_in[param_band_idx]; -#endif + Cx_state = Cx_in[param_band_idx]; Cx_old_state = hParamMC->h_output_synthesis_cov_state.cx_old[param_band_idx]; Cy_old_state = hParamMC->h_output_synthesis_cov_state.cy_old[param_band_idx]; + set_zero( Nrqq, MAX_OUTPUT_CHANNELS ); set_zero( target_ch_ener, MAX_OUTPUT_CHANNELS ); set_zero( Cy_full, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); @@ -2767,7 +2799,86 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( { set_zero( mixing_matrix_res[param_band_idx], nY_cov * nY_cov ); } -#ifndef FIX_835_PARAMMC_BUFFER_VALUES + } + +#else + + float Cy_full[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + float mixing_matrix_woLFE[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + float Nrqq[MAX_OUTPUT_CHANNELS]; + float target_ch_ener[MAX_OUTPUT_CHANNELS]; + int16_t k, l; + float *ild_q; + + Cx_state = Cx_in; + Cx_old_state = hParamMC->h_output_synthesis_cov_state.cx_old[param_band_idx]; + Cy_old_state = hParamMC->h_output_synthesis_cov_state.cy_old[param_band_idx]; + set_zero( Nrqq, MAX_OUTPUT_CHANNELS ); + set_zero( target_ch_ener, MAX_OUTPUT_CHANNELS ); + set_zero( Cy_full, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + set_zero( Cy_state, MAX_CICP_CHANNELS * MAX_CICP_CHANNELS ); + set_zero( Cproto_diag, MAX_CICP_CHANNELS ); + ild_q = hParamMC->icld_q + param_band_idx * hParamMC->hMetadataPMC->ild_mapping_conf->ild_map_size_lfe; + + /*get back Nrg*/ + for ( k = 0; k < nY_intern; k++ ) + { + float ref_ener = 0.0f; + int16_t ref_channel_cnt; + int16_t ref_channel_idx; + + for ( ref_channel_cnt = 0; ref_channel_cnt < hParamMC->hMetadataPMC->ild_mapping_conf->num_ref_channels[k]; ref_channel_cnt++ ) + { + ref_channel_idx = hParamMC->hMetadataPMC->ild_mapping_conf->ref_channel_idx[k][ref_channel_cnt]; + ref_ener += Cx_state[ref_channel_idx + ref_channel_idx * nX]; + } + Nrqq[hParamMC->hMetadataPMC->ild_mapping_conf->ild_index[k]] = powf( 10.0f, ild_q[k] / 10.0f ) * hParamMC->hMetadataPMC->ild_factors[k] * ref_ener; + } + for ( k = 0; k < nY_cov; k++ ) + { + for ( l = 0; l < nY_intern; l++ ) + { + target_ch_ener[k] += hParamMC->ls_conv_dmx_matrix[k + l * nY_cov] * Nrqq[l]; + } + Cy_state[k + nY_cov * k] = target_ch_ener[k]; + } + + /* Smoothing: Sum over two buffers */ + if ( hParamMC->hMetadataPMC->bAttackPresent ) + { + /* no smoothing on attacks */ + mvr2r( Cx_state, Cx, nX * nX ); + mvr2r( Cy_state, Cy_full, nY_cov * nY_cov ); + } + else + { + /* smoothing gains are now identical to one, simply add up */ + v_add( Cx_state, Cx_old_state, Cx, nX * nX ); + v_add( Cy_state, Cy_old_state, Cy_full, nY_cov * nY_cov ); + } + + /* cov buffer update */ + mvr2r( Cx_state, Cx_old_state, nX * nX ); + mvr2r( Cy_state, Cy_old_state, nY_cov * nY_cov ); + + + matrix_product( proto_matrix, nY_band, nX, 0, Cx, nX, nX, 0, mat_mult_buffer1 ); + + matrix_product_diag( mat_mult_buffer1, nY_band, nX, 0, proto_matrix, nY_band, nX, 1, Cproto_diag ); + + /* Computing the mixing matrices */ + for ( i = 0; i < nY_band; i++ ) + { + Cy_diag[i] = Cy_full[i + nY_band * i]; + Cy_diag[i] = sqrtf( Cy_diag[i] / ( Cproto_diag[i] + EPSILON ) ); + } + + diag_matrix_product( Cy_diag, nY_band, proto_matrix, nY_band, nX, 0, mixing_matrix_woLFE ); + + mvr2r( mixing_matrix_woLFE, mixing_matrix[param_band_idx], nY_cov * nX ); + if ( hParamMC->band_grouping[param_band_idx] < hParamMC->h_output_synthesis_params.max_band_decorr ) + { + set_zero( mixing_matrix_res[param_band_idx], nY_cov * nY_cov ); } #endif -- GitLab From 7ab8e2fb7b9828710892bba754387cbb83be6d98 Mon Sep 17 00:00:00 2001 From: malenov Date: Mon, 4 Nov 2024 14:48:32 +0100 Subject: [PATCH 2/2] fix data declaration section --- lib_dec/ivas_mc_param_dec.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index 30927bfaf..5a321314b 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -2698,6 +2698,13 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( #ifndef FIX_835_PARAMMC_BUFFER_VALUES int16_t param_band_idx; #endif + float Cy_full[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; + float mixing_matrix_woLFE[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; + float Nrqq[MAX_OUTPUT_CHANNELS]; + float target_ch_ener[MAX_OUTPUT_CHANNELS]; + int16_t k, l; + float *ild_q; + float Cx[PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS]; float Cy_diag[MAX_CICP_CHANNELS]; float Cproto_diag[MAX_CICP_CHANNELS]; @@ -2721,13 +2728,6 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( #ifndef FIX_835_PARAMMC_BUFFER_VALUES for ( param_band_idx = 0; param_band_idx < hParamMC->num_param_bands_synth; param_band_idx++ ) { - float Cy_full[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; - float mixing_matrix_woLFE[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; - float Nrqq[MAX_OUTPUT_CHANNELS]; - float target_ch_ener[MAX_OUTPUT_CHANNELS]; - int16_t k, l; - float *ild_q; - Cx_state = Cx_in[param_band_idx]; Cx_old_state = hParamMC->h_output_synthesis_cov_state.cx_old[param_band_idx]; Cy_old_state = hParamMC->h_output_synthesis_cov_state.cy_old[param_band_idx]; @@ -2803,13 +2803,6 @@ static void ivas_param_mc_get_mono_stereo_mixing_matrices( #else - float Cy_full[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; - float mixing_matrix_woLFE[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; - float Nrqq[MAX_OUTPUT_CHANNELS]; - float target_ch_ener[MAX_OUTPUT_CHANNELS]; - int16_t k, l; - float *ild_q; - Cx_state = Cx_in; Cx_old_state = hParamMC->h_output_synthesis_cov_state.cx_old[param_band_idx]; Cy_old_state = hParamMC->h_output_synthesis_cov_state.cy_old[param_band_idx]; -- GitLab