diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 11e1fb89ae556a0d3ae5b09ae4f6cfef1328bbc3..18bd70f5142748919768222962c43e48ce13b81e 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -114,6 +114,10 @@ ivas_error core_switching_pre_dec_ivas_fx( IF( st->hBWE_TD != NULL && NE_16( st->last_core, ACELP_CORE ) ) { +#ifdef MSAN_FIX + st->hBWE_TD->prev_hb_synth_fx_exp = 31; + move16(); +#endif // MSAN_FIX /* reset BWE memories */ set16_fx( st->hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); st->hBWE_TD->bwe_non_lin_prev_scale_fx = 0; diff --git a/lib_dec/dec_uv_fx.c b/lib_dec/dec_uv_fx.c index 3ab65b7280aea1bf68163cfdda51d96a3d745a2e..cc33c23b0e76619ed32ccb9956d89e05e046eabf 100644 --- a/lib_dec/dec_uv_fx.c +++ b/lib_dec/dec_uv_fx.c @@ -294,10 +294,9 @@ static void gain_dec_gacelp_uv_fx( /* gain_inov = 1.0f / sqrt((dot_product(code, code, L_SUBFR) + 0.01) / L_SUBFR) */ L_tmp = calc_gain_inov(code, lcode, NULL, NULL); *gain_inov = round_fx(L_shl(L_tmp, 15 - 3)); /* gain_inov in Q12 */ - /* gcode = pred_nrg_frame * (*gain_inov); */ L_tmp = Mpy_32_16_1(pred_nrg_frame, *gain_inov); /* 18Q13 */ - i = norm_l(L_tmp); + i = sub(norm_l(L_tmp),1); //gaurd-bits g_code = round_fx(L_shl(L_tmp, i)); exp_gcode = sub(18, i); diff --git a/lib_dec/init_dec_fx.c b/lib_dec/init_dec_fx.c index bc1fb287de9afcbedbf315c3c8d8bc8989659391..ef0539a2448000fa6b0d63595149746bbf9232f7 100644 --- a/lib_dec/init_dec_fx.c +++ b/lib_dec/init_dec_fx.c @@ -529,6 +529,9 @@ ivas_error init_decoder_fx( #endif st_fx->output_Fs); +#ifdef MSAN_FIX + st_fx->hBWE_TD->prev_hb_synth_fx_exp = 31; +#endif } ELSE { @@ -1279,6 +1282,9 @@ ivas_error init_decoder_ivas_fx( } hf_synth_init_fx(st_fx->hBWE_zero); +#ifdef MSAN_FIX + set16_fx( st_fx->hBWE_zero->mem_hp400_fx, 0, 6 ); +#endif } ELSE { @@ -1424,6 +1430,9 @@ ivas_error init_decoder_ivas_fx( } td_bwe_dec_init_ivas_fx(st_fx, st_fx->hBWE_TD, st_fx->output_Fs); +#ifdef MSAN_FIX + st_fx->hBWE_TD->prev_hb_synth_fx_exp = 31; +#endif } ELSE { diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 143d8e2b8b363b9db1ed6d39fc30f7abdcc73e71..ff1a6655f22f5c0602c55310d9f6e33f67f7f078 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -5523,13 +5523,13 @@ void ivas_dirac_dec_render_sf_fx( st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q6 - 1; move16(); - // Scaling the output to Q10 - scale_sig32(output_buf_fx[ch], samplesToProcess + index_slot * hSpatParamRendCom->num_freq_bands, Q10 - Q11 ); + // Scaling the output to Q8 + scale_sig32(output_buf_fx[ch], samplesToProcess + index_slot * hSpatParamRendCom->num_freq_bands, Q8 - Q11 ); cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, p_out, samplesToProcess, st_ivas->cldfbSynDec[idx_in] ); - // Scaling output from Q6-1 to Q10 - scale_sig32(p_out, out_len, (Q10 - (Q6 - 1))); + // Scaling output from Q6-1 to Q8 + scale_sig32(p_out, out_len, (Q8 - (Q6 - 1))); #if 1 /* TODO: remove fixed to float */ fixedToFloat_arrL(st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_state, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state, st_ivas->cldfbSynDec[idx_in]->p_filter_length); @@ -5846,7 +5846,7 @@ void ivas_dirac_dec_render_sf_fx( ELSE { // Fixed to float - fixedToFloat_arrL(output_buf_fx[ch], output_f[ch], Q10, hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] + index_slot * hSpatParamRendCom->num_freq_bands); + fixedToFloat_arrL(output_buf_fx[ch], output_f[ch], Q8, hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx] + index_slot * hSpatParamRendCom->num_freq_bands); } } } diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 823eaae5faeb6641fa5b2ad7baa32654c0ecdeba..a9bcb7f64bd1862337f10fd170c050711845462e 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -715,6 +715,9 @@ static ivas_error ivas_param_ism_rendering_init( { set32_fx( hParamIsmRendering->mixing_matrix_lin_old_fx[bin_idx], 0, PARAM_ISM_MAX_CHAN * PARAM_ISM_MAX_DMX ); } +#ifdef MSAN_FIX + hParamIsmRendering->exp_mixing_matrix_lin_old_fx = 0; +#endif /* memory allocation for proto matrix and interpolator */ if ( ( hParamIsmRendering->proto_matrix = (float *) malloc( hOutSetup.nchan_out_woLFE * nchan_transport * sizeof( float ) ) ) == NULL ) @@ -2044,6 +2047,7 @@ void ivas_param_ism_dec_digest_tc( { #ifdef IVAS_FLOAT_FIXED ivas_param_ism_dec_dequant_DOA_fx( hParamIsmDec, st_ivas->nchan_ism ); +#ifndef MSAN_FIX for ( i = 0; i < 11; i++ ) { for ( int j = 0; j < 1; j++ ) @@ -2054,6 +2058,7 @@ void ivas_param_ism_dec_digest_tc( } } } +#endif ivas_param_ism_dec_dequant_powrat_fx( hParamIsmDec ); for ( i = 0; i < 11; i++ ) { diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 6eade55534d97e3cb6bc4fd6f332fa7885971f1e..2a7614384d65ec1795cfae8c4bbaa82d4f7a5344 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -3203,6 +3203,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( #if 1 /*Float to fix */ PARAM_ISM_DEC_HANDLE hParamIsmDec; hParamIsmDec = st_ivas->hParamIsmDec; +#ifndef IVAS_FLOAT_FIXED FOR( i = 0; i < 11; i++ ) { FOR( Word16 j = 0; j < 1; j++ ) @@ -3213,6 +3214,7 @@ void ivas_jbm_dec_feed_tc_to_renderer( } } } +#endif // st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_fx = float_to_fix16( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->coherence_flt, 15 ); SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; hSpatParamRendCom = st_ivas->hSpatParamRendCom; @@ -4554,6 +4556,16 @@ ivas_error ivas_jbm_dec_render( else if ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) { /* Convert to Ambisonics; used also for ISM->HOA3->binaural rendering */ +#ifdef MSAN_FIX + FOR( i = 0; i < st_ivas->nchan_transport; i++ ) + { + FOR( j = 0; j < 16; j++ ) + { + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29 + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29 + } + } +#else FOR( i = 0; i < 15; i++ ) { FOR( j = 0; j < 16; j++ ) @@ -4562,6 +4574,7 @@ ivas_error ivas_jbm_dec_render( st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29 } } +#endif Word16 Q_buffer_in = 31; FOR( i = 0; i < st_ivas->nchan_transport; i++ ) { @@ -4578,6 +4591,16 @@ ivas_error ivas_jbm_dec_render( fixedToFloat_arrL( p_output_fx[j], p_output[j], Q_buffer_in + 29 - 31, *nSamplesRendered ); } +#ifdef MSAN_FIX + FOR( i = 0; i < st_ivas->nchan_transport; i++ ) + { + FOR( j = 0; j < 16; j++ ) + { + st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30 + st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30 + } + } +#else FOR( i = 0; i < 15; i++ ) { FOR( j = 0; j < 16; j++ ) @@ -4586,6 +4609,7 @@ ivas_error ivas_jbm_dec_render( st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30 } } +#endif } /* Binaural rendering */ diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 7ee3f1e7e2a91d2ab5f8354ac651dd0735de7e0d..8e54110734be949333f35e59d5cc5b62c54d7581 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -1292,8 +1292,22 @@ void ivas_omasa_dirac_rend_jbm( Word16 q_output = 31; Word32 **output_fx, data_separated_objects_fx[4][960]; q_output = Q11; +#ifdef MSAN_FIX/*Can be removed when dependency on data_separated_objects is removed*/ + Word16 no_channels; + IF ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + no_channels = 1; + } + ELSE + { + no_channels = st_ivas->nchan_ism; + } + FOR( Word16 ind = 0; ind < no_channels; ind++ ) + { +#else FOR(Word16 ind = 0; ind < MAX_NUM_OBJECTS; ind++) { +#endif // MSAN_FIX FOR(Word16 ind2 = 0; ind2 < nSamplesAsked; ind2++) { //data_separated_objects_fx[ind][ind2] = (Word32)(data_separated_objects[ind][ind2] * (1<proto_power_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir; } IF ( dirac_output_synthesis_params->max_band_decorr > 0 && ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) ) { @@ -212,6 +213,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->proto_power_diff_smooth_prev_len = dirac_output_synthesis_params->max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE; } ELSE { @@ -250,6 +252,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->cy_cross_dir_smooth_prev_len = size; IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /*TODO : remove float code*/ @@ -263,6 +266,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->cy_auto_dir_smooth_prev_len = dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff; } ELSE { @@ -290,6 +294,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->cy_auto_dir_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; IF( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { @@ -297,6 +302,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->cy_auto_diff_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } ELSE { @@ -304,6 +310,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->cy_auto_diff_smooth_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff; } } @@ -317,7 +324,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } - + dirac_output_synthesis_state->gains_dir_prev_len = size; IF ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { /*TODO : remove float code*/ @@ -329,6 +336,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->gains_diff_prev_len = dirac_output_synthesis_params->max_band_decorr * hDirACRend->num_outputs_diff; } ELSE IF ( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_PSD_SHD && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_MONO ) { @@ -341,6 +349,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->gains_diff_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff; } ELSE { @@ -353,6 +362,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } + dirac_output_synthesis_state->gains_diff_prev_len = hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir; } /*-----------------------------------------------------------------* @@ -401,6 +411,7 @@ ivas_error ivas_dirac_dec_output_synthesis_open_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis\n" ) ); } set32_fx( dirac_output_synthesis_state->reference_power_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands ); + dirac_output_synthesis_state->reference_power_smooth_prev_q = Q31; set32_fx( dirac_output_synthesis_state->direction_smoothness_prev_fx, 0, hSpatParamRendCom->num_freq_bands ); /*TODO : remove float code*/ @@ -967,6 +978,7 @@ void ivas_dirac_dec_output_synthesis_init_fx( IF( h_dirac_output_synthesis_state->proto_power_smooth_prev_fx != NULL ) { set32_fx( h_dirac_output_synthesis_state->proto_power_smooth_prev_fx, 0, hSpatParamRendCom->num_freq_bands * hDirACRend->num_protos_dir ); + h_dirac_output_synthesis_state->proto_power_smooth_prev_q = Q31; } set32_fx( h_dirac_output_synthesis_state->gains_dir_prev_fx, 0, size ); h_dirac_output_synthesis_state->gains_dir_prev_q = 0; @@ -985,6 +997,7 @@ void ivas_dirac_dec_output_synthesis_init_fx( { set32_fx( h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_fx, 0, h_dirac_output_synthesis_params->max_band_decorr * nchan_out_woLFE ); } + h_dirac_output_synthesis_state->proto_power_diff_smooth_prev_q = Q31; #endif return; @@ -3183,10 +3196,13 @@ void ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( { q_com = s_min( *q_reference_power_smooth, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); scale_sig32( reference_power_smooth, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); + scale_sig32( h_dirac_output_synthesis_state->reference_power_smooth_prev_fx, num_freq_bands, sub( q_com, *q_reference_power_smooth ) ); scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, i_mult( num_freq_bands, nchan_target_psds ), sub( q_com, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); *q_reference_power_smooth = q_com; + h_dirac_output_synthesis_state->reference_power_smooth_prev_q = q_com; + move16(); h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = q_com; move16(); @@ -6283,9 +6299,24 @@ static void computeTargetPSDs_diffuse_with_onsets_fx( Word32 diffuse_power[CLDFB_NO_CHANNELS_MAX]; /* size: num_freq_bands. */ Word32 aux_buffer_res[CLDFB_NO_CHANNELS_MAX]; /* size: num_freq_bands. */ + Word16 q_common, q_reference_power_min_one; + + q_reference_power_min_one = sub( *q_reference_power, Q1 ); + /* estimate direct and diffuse power */ v_mult_fixed( diffuse_power_factor, reference_power, diffuse_power, num_decorr_freq_bands ); // (Q31, q_reference_power) -> q_reference_power + IF( GT_16( *q_cy_auto_diff_smooth, q_reference_power_min_one ) ) + { + q_common = q_reference_power_min_one; + move16(); + } + ELSE + { + q_common = *q_cy_auto_diff_smooth; + move16(); + } + /* compute target auto and cross PSDs of current frame (smoothed) */ FOR( ch_idx = 0; ch_idx < num_channels; ++ch_idx ) { @@ -6300,13 +6331,21 @@ static void computeTargetPSDs_diffuse_with_onsets_fx( v_multc_fixed( aux_buffer_res, diffuse_response_p4, aux_buffer_res, num_decorr_freq_bands ); // (Q30, Q31) -> Q30 v_add_fixed( aux_buffer_res1, aux_buffer_res, aux_buffer_res, num_decorr_freq_bands, 0 ); // Q30 v_mult_fixed( aux_buffer_res, diffuse_power, aux_buffer_res, num_decorr_freq_bands ); // (Q30, q_reference_power) -> q_reference_power - Q1 - Scale_sig32( aux_buffer_res, num_decorr_freq_bands, sub( *q_cy_auto_diff_smooth, sub( *q_reference_power, Q1 ) ) ); // q_cy_auto_diff_smooth - v_add_fixed( &cy_auto_diff_smooth[cur_idx], aux_buffer_res, &cy_auto_diff_smooth[cur_idx], num_decorr_freq_bands, Q1 ); // (q_cy_auto_diff_smooth - Q1) - Scale_sig32( &cy_auto_diff_smooth[cur_idx + num_decorr_freq_bands], sub( num_freq_bands, num_decorr_freq_bands ), negate( Q1 ) ); // (q_cy_auto_diff_smooth - Q1) + + IF( NE_16( q_common, q_reference_power_min_one ) ) + { + scale_sig32( aux_buffer_res, num_decorr_freq_bands, sub( q_common, q_reference_power_min_one ) ); // q_common + } + IF( NE_16( q_common, *q_cy_auto_diff_smooth ) ) + { + scale_sig32( &cy_auto_diff_smooth[cur_idx], num_decorr_freq_bands, sub( q_common, *q_cy_auto_diff_smooth ) ); // q_common + } + v_add_fixed( &cy_auto_diff_smooth[cur_idx], aux_buffer_res, &cy_auto_diff_smooth[cur_idx], num_decorr_freq_bands, Q1 ); // (q_common - Q1) + scale_sig32( &cy_auto_diff_smooth[cur_idx + num_decorr_freq_bands], sub( num_freq_bands, num_decorr_freq_bands ), sub( sub( q_common, Q1 ), *q_cy_auto_diff_smooth ) ); // (q_common - Q1) } /* Q adjustment */ - *q_cy_auto_diff_smooth = sub( *q_cy_auto_diff_smooth, Q1 ); + *q_cy_auto_diff_smooth = sub( q_common, Q1 ); move16(); return; diff --git a/lib_rend/ivas_dirac_rend.c b/lib_rend/ivas_dirac_rend.c index bd03007119c580e35615c838cc59f9a619ccfff4..94cd7e02a12f372115b001743b69c4a8e8cc16d2 100644 --- a/lib_rend/ivas_dirac_rend.c +++ b/lib_rend/ivas_dirac_rend.c @@ -1506,6 +1506,7 @@ ivas_error ivas_dirac_alloc_mem( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero_fx( hDirAC_mem->cy_auto_dir_smooth_fx, size ); + hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len = size; #endif if ( ( hDirAC_mem->proto_power_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) @@ -1519,8 +1520,8 @@ ivas_error ivas_dirac_alloc_mem( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero_fx( hDirAC_mem->proto_power_smooth_fx, size ); + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len = size; #endif - if ( ( hDirAC_mem->proto_power_diff_smooth = (float *) malloc( sizeof( float ) * size ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); @@ -1603,10 +1604,12 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } + hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len = size_ho; #ifdef MSAN_FIX set_zero_fx( hDirAC_mem->cy_cross_dir_smooth_fx, size_ho ); #else set_zero_fx( hDirAC_mem->cy_cross_dir_smooth_fx, size ); + hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len = size_ho; #endif #endif @@ -1623,6 +1626,7 @@ ivas_error ivas_dirac_alloc_mem( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero_fx( hDirAC_mem->cy_auto_diff_smooth_fx, size ); + hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = size; #endif } else @@ -1638,6 +1642,7 @@ ivas_error ivas_dirac_alloc_mem( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } set_zero_fx( hDirAC_mem->cy_auto_diff_smooth_fx, num_outputs_diff * num_freq_bands_diff ); + hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len = num_outputs_diff * num_freq_bands_diff; #endif } hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth = hDirAC_mem->cy_cross_dir_smooth; @@ -1692,6 +1697,8 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } + + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len = 2 * MAX_PARAM_SPATIAL_SUBFRAMES * num_protos_dir * num_freq_bands; #endif if ( hDirACRend->proto_signal_decorr_on ) @@ -1799,6 +1806,10 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } + + hDirAC_mem->reference_power_len = 2 * num_freq_bands; + hDirAC_mem->reference_power_q = Q31; + hDirAC_mem->reference_power_smooth_q = Q31; #endif if ( hDirACRend->proto_signal_decorr_on ) { @@ -1815,6 +1826,7 @@ ivas_error ivas_dirac_alloc_mem( set_zero( hDirAC_mem->onset_filter, num_outputs_diff * num_freq_bands); set_zero_fx( hDirAC_mem->onset_filter_fx, num_outputs_diff * num_freq_bands ); #endif + hDirAC_mem->onset_filter_len = 2 * num_freq_bands; #endif } } @@ -1832,6 +1844,8 @@ ivas_error ivas_dirac_alloc_mem( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate stack memory for DirAC\n" ) ); } + + hDirAC_mem->reference_power_len = 5 * num_freq_bands; #endif } @@ -1850,6 +1864,7 @@ ivas_error ivas_dirac_alloc_mem( set_zero( hDirAC_mem->onset_filter, 2 * num_freq_bands ); set_zero_fx( hDirAC_mem->onset_filter_fx, 2 * num_freq_bands ); #endif + hDirAC_mem->onset_filter_len = 2 * num_freq_bands; #endif } } @@ -3010,7 +3025,11 @@ void protoSignalComputation2_fx( q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], num_freq_bands ), L_norm_arr( ImagBuffer_fx[l][0], num_freq_bands ) ); min_q_shift = s_min( min_q_shift, q_shift ); +#ifdef MSAN_FIX + q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], s_min(num_freq_bands, MASA_SUM_FREQ_RANGE_BINS)), L_norm_arr( ImagBuffer_fx[l][0], s_min(num_freq_bands, MASA_SUM_FREQ_RANGE_BINS)) ); +#else q_shift = s_min( L_norm_arr( RealBuffer_fx[l][0], MASA_SUM_FREQ_RANGE_BINS ), L_norm_arr( ImagBuffer_fx[l][0], MASA_SUM_FREQ_RANGE_BINS ) ); +#endif // MSAN_FIX temp_q_shift = s_min( temp_q_shift, q_shift ); } @@ -4685,6 +4704,7 @@ void ivas_masa_init_stereotype_detection_fx( stereo_type_detect->subtract_power_y_fx = 0; stereo_type_detect->q_subtract_power_y = Q31; stereo_type_detect->subtract_power_y_smooth_fx = 0; + stereo_type_detect->q_subtract_power_y_smooth = Q31; stereo_type_detect->target_power_y_smooth_fx = 0; stereo_type_detect->lr_total_bb_ratio_db_fx = 0; @@ -5440,6 +5460,7 @@ void rotateAziEle_DirAC( } /* A reduced rewrite of the corresponding decoder side function */ +#ifndef IVAS_FLOAT_FIXED static void ivas_masa_ext_dirac_render_sf( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */ float *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ @@ -5715,35 +5736,7 @@ static void ivas_masa_ext_dirac_render_sf( if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD ) { /* Compute diffuse prototypes */ -#ifdef IVAS_FLOAT_FIXED_u - /* Float to fixed */ - if (hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0) - { - f2me_buf(hDirACRend->proto_frame_dec_f, hDirACRend->proto_frame_dec_f_fx, &hDirACRend->proto_frame_dec_f_q, hDirACRend->proto_frame_dec_f_len); - hDirACRend->proto_frame_dec_f_q = 31 - hDirACRend->proto_frame_dec_f_q; - DIRAC_OUTPUT_SYNTHESIS_STATE *state = &(hDirACRend->h_output_synthesis_psd_state); - f2me_buf(state->proto_power_diff_smooth, state->proto_power_diff_smooth_fx, &state->proto_power_diff_smooth_q, state->proto_power_diff_smooth_len); - state->proto_power_diff_smooth_q = 31 - state->proto_power_diff_smooth_q; - f2me_buf(state->proto_diffuse_buffer_f, state->proto_diffuse_buffer_f_fx, &state->proto_diffuse_buffer_f_q, state->proto_diffuse_buffer_f_len); - state->proto_diffuse_buffer_f_q = 31 - state->proto_diffuse_buffer_f_q; - } - ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); - /* Fixed to float */ - if (hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0) - { - DIRAC_OUTPUT_SYNTHESIS_STATE *state = &(hDirACRend->h_output_synthesis_psd_state); - me2f_buf(state->proto_power_diff_smooth_fx, - 31 - state->proto_power_diff_smooth_q, - state->proto_power_diff_smooth, - state->proto_power_diff_smooth_len); - me2f_buf(state->proto_diffuse_buffer_f_fx, - 31 - state->proto_diffuse_buffer_f_q, - state->proto_diffuse_buffer_f, - state->proto_diffuse_buffer_f_len); - } -#else ivas_dirac_dec_compute_diffuse_proto( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); -#endif } ivas_dirac_dec_output_synthesis_process_slot( reference_power, @@ -5768,13 +5761,7 @@ static void ivas_masa_ext_dirac_render_sf( } } -#ifdef IVAS_FLOAT_FIXED - ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); - fixedToFloat_arr( hDirACRend->h_output_synthesis_psd_params.interpolator_fx, hDirACRend->h_output_synthesis_psd_params.interpolator, Q15, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); -#else ivas_dirac_dec_output_synthesis_get_interpolator( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); -#endif - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { @@ -5852,38 +5839,47 @@ static void ivas_masa_ext_dirac_render_sf( return; } -#ifdef IVAS_FLOAT_FIXED_u //Currently disabled +#else static void ivas_masa_ext_dirac_render_sf_fx( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: IVAS decoder structure */ - Word32 *output_f[] /* i/o: synthesized core-coder transport channels/DirAC output */ + Word32 *output_f_fx[] /* i/o: synthesized core-coder transport channels/DirAC output */ ) { - int16_t i, ch, idx_in, idx_lfe; + Word16 i, ch, idx_in, idx_lfe; DIRAC_REND_HANDLE hDirACRend; - Word32 dirEne; - Word32 surCohEner; - Word16 surCohRatio[CLDFB_NO_CHANNELS_MAX]; - Word16 surCohRatio_exp; Word16 subframe_idx; Word16 slot_idx, index_slot; Word16 slot_idx_start, slot_idx_start_cldfb_synth, md_idx; - Word16 nchan_transport, q_cldfb; + Word16 nchan_transport; Word16 masa_band_mapping[MASA_FREQUENCY_BANDS + 1]; - /* CLDFB: last output channels reserved to LFT for CICPx */ - Word32 Cldfb_RealBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - Word32 Cldfb_ImagBuffer[MAX_OUTPUT_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; - /* local copies of azi, ele, diffuseness */ Word16 azimuth[CLDFB_NO_CHANNELS_MAX]; Word16 elevation[CLDFB_NO_CHANNELS_MAX]; - Word32 diffuseness_vector[CLDFB_NO_CHANNELS_MAX]; + + Word32 diffuseness_vector_fx[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]; + Word16 q_cldfb = 0; + Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX]; + Word16 Q_surCohRatio, surCohRatio_exp[CLDFB_NO_CHANNELS_MAX]; + Word32 dirEne_fx; + Word32 surCohEner_fx; + + FOR(Word16 ii = 0; ii < MAX_OUTPUT_CHANNELS; ii++) + { + FOR(Word16 jj = 0; jj < MAX_PARAM_SPATIAL_SUBFRAMES; jj++) + { + set_zero_fx( Cldfb_RealBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX ); + set_zero_fx( Cldfb_ImagBuffer_fx[ii][jj], CLDFB_NO_CHANNELS_MAX ); + } + } DIRAC_DEC_STACK_MEM DirAC_mem; - Word32 *reference_power, *reference_power_smooth; - Word16 q_reference_power; - Word32 *onset_filter, *onset_filter_subframe, *p_onset_filter = NULL; - uint16_t coherence_flag; + + Word32 *onset_filter_fx, *onset_filter_subframe_fx, *p_onset_filter_fx = NULL; + Word32 *reference_power_smooth_fx, *reference_power_fix; + UWord16 coherence_flag; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; push_wmops( "ivas_masa_ext_dirac_render_sf" ); @@ -5891,20 +5887,21 @@ static void ivas_masa_ext_dirac_render_sf_fx( /* Initialize aux buffers */ hDirACRend = hMasaExtRend->hDirACRend; hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - nchan_transport = hMasaExtRend->nchan_input; - move16(); + nchan_transport = hMasaExtRend->nchan_input; move16(); + DirAC_mem = hDirACRend->stack_mem; - reference_power = DirAC_mem.reference_power_fx; move32(); - reference_power_smooth = ( DirAC_mem.reference_power_fx == NULL ) ? NULL : DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; - onset_filter = DirAC_mem.onset_filter_fx; - onset_filter_subframe = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + onset_filter_fx = DirAC_mem.onset_filter_fx; + reference_power_fix = 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; + //DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q = Q31; + onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; coherence_flag = 1; /* There is always coherence assumed for ext rend of MASA */ move16(); /* Construct default MASA band mapping */ FOR ( i = 0; i < MASA_FREQUENCY_BANDS + 1; i++ ) { - masa_band_mapping[i] = i; move16(); + masa_band_mapping[i] = i; move16(); } /* Subframe loop */ @@ -5914,44 +5911,61 @@ static void ivas_masa_ext_dirac_render_sf_fx( subframe_idx = hSpatParamRendCom->subframes_rendered; move16(); md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); + DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); + /* copy parameters into local buffers*/ + 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 ); - Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector, hSpatParamRendCom->num_freq_bands ); + Copy32( hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[subframe_idx]], diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands ); IF ( NE_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) { - set32_fx( reference_power_smooth, 0, hSpatParamRendCom->num_freq_bands ); + set32_fx( reference_power_smooth_fx, 0, hSpatParamRendCom->num_freq_bands ); } ELSE { - set32_fx( onset_filter_subframe, 0, hSpatParamRendCom->num_freq_bands ); + set32_fx( onset_filter_subframe_fx, 0, hSpatParamRendCom->num_freq_bands ); } /* compute response */ IF ( NE_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) { ivas_dirac_dec_compute_power_factors_fx( hSpatParamRendCom->num_freq_bands, - diffuseness_vector, - 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 ); + 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 ); + + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q29; move16(); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q29; move16(); + IF ( coherence_flag ) { + Word16 temp_exp = MIN_16; move16(); FOR ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - dirEne = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; move32(); - surCohEner = Mpy_32_16_1(hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]); //Q.31 - 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); - 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); + dirEne_fx = hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i]; move32(); + surCohEner_fx = Mpy_32_16_1(hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]); //Q.29 + 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); + 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); - surCohRatio[i] = BASOP_Util_Divide3232_Scale( surCohEner, L_add( L_add(1, dirEne), surCohEner ), &surCohRatio_exp); + surCohRatio_fx[i] = L_deposit_h(BASOP_Util_Divide3232_Scale( surCohEner_fx, L_add( L_add(1, dirEne_fx), surCohEner_fx ), &surCohRatio_exp[i])); + temp_exp = s_max(temp_exp, surCohRatio_exp[i]); } + + FOR(i = 0; i < hSpatParamRendCom->num_freq_bands; i++) + { + surCohRatio_fx[i] = L_shr(surCohRatio_fx[i], sub(temp_exp, surCohRatio_exp[i])); + } + Q_surCohRatio = sub(31, temp_exp); } ELSE { - set16_fx( surCohRatio, 0, hSpatParamRendCom->num_freq_bands ); + set32_fx( surCohRatio_fx, 0, hSpatParamRendCom->num_freq_bands ); + Q_surCohRatio = 31; move16(); } } ELSE @@ -5961,20 +5975,23 @@ static void ivas_masa_ext_dirac_render_sf_fx( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, &hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q, - &hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q + &hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q ); - + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = sub(31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = sub(31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q); IF ( coherence_flag ) { FOR ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - surCohRatio[i] = hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]; move16(); + surCohRatio_fx[i] = L_deposit_h(hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]); move16(); } } ELSE { - set16_fx( surCohRatio, 0, hSpatParamRendCom->num_freq_bands ); + set32_fx( surCohRatio_fx, 0, hSpatParamRendCom->num_freq_bands ); } + + Q_surCohRatio = Q31; move16(); } ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, @@ -5985,94 +6002,137 @@ static void ivas_masa_ext_dirac_render_sf_fx( azimuth, elevation, md_idx, - surCohRatio, - surCohRatio_exp, + surCohRatio_fx, + Q_surCohRatio, 0, NULL, 0 ); + Word16 proto_direct_buffer_f_temp_q[60]; + Word16 temp_proto_frame_q; FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { index_slot = add(slot_idx_start, slot_idx); md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); + proto_direct_buffer_f_temp_q[slot_idx] = MAX_16; move16(); /* CLDFB Analysis*/ FOR ( ch = 0; ch < nchan_transport; ch++ ) { - cldfbAnalysis_ts_fx( &( output_f[ch][hSpatParamRendCom->num_freq_bands * index_slot] ), - Cldfb_RealBuffer[ch][0], - Cldfb_ImagBuffer[ch][0], - hSpatParamRendCom->num_freq_bands, - hMasaExtRend->cldfbAnaRend[ch], q_cldfb); + q_cldfb = 11; move16(); + hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = q_cldfb; move16(); + cldfbAnalysis_ts_fx_fixed_q( &( output_f_fx[ch][hSpatParamRendCom->num_freq_bands * index_slot] ) , + Cldfb_RealBuffer_fx[ch][0], + Cldfb_ImagBuffer_fx[ch][0], + hSpatParamRendCom->num_freq_bands, + hMasaExtRend->cldfbAnaRend[ch], &q_cldfb ); } - IF ( EQ_16(nchan_transport, 1 )) { /* Need to set second CLDFB channel to zero as further processing assumes CNA content in it */ - set16_fx( Cldfb_RealBuffer[1][0], 0, hSpatParamRendCom->num_freq_bands ); - set16_fx( Cldfb_ImagBuffer[1][0], 0, hSpatParamRendCom->num_freq_bands ); + set32_fx( Cldfb_RealBuffer_fx[1][0], 0, hSpatParamRendCom->num_freq_bands ); + set32_fx( Cldfb_ImagBuffer_fx[1][0], 0, hSpatParamRendCom->num_freq_bands ); } - /*-----------------------------------------------------------------* * prototype signal computation *-----------------------------------------------------------------*/ IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) { - protoSignalComputation_shd_fx( Cldfb_RealBuffer, Cldfb_ImagBuffer, + protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, - reference_power, q_reference_power, slot_idx, nchan_transport, + reference_power_fix, &DirAC_mem.reference_power_q, slot_idx, nchan_transport, hDirACRend->num_outputs_diff, hSpatParamRendCom->num_freq_bands, 0, q_cldfb); - } + + proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); + } ELSE IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO )) { - protoSignalComputation2_fx( Cldfb_RealBuffer, Cldfb_ImagBuffer, hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_q, + protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx, &hDirACRend->proto_frame_f_q, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, - reference_power, q_reference_power, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, 0, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect, q_cldfb); + + proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); + IF(LT_16(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)){ + Scale_sig32(reference_power_fix + hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands), sub(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); + } ELSE { + Scale_sig32(reference_power_fix, hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q)); + DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); + } + temp_proto_frame_q = getScaleFactor32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len) - 2; + Scale_sig32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q); + hDirACRend->proto_frame_f_q = add(hDirACRend->proto_frame_f_q, temp_proto_frame_q); } ELSE { SWITCH ( nchan_transport ) { case 2: - protoSignalComputation2_fx( Cldfb_RealBuffer, Cldfb_ImagBuffer, + protoSignalComputation2_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx, - hDirACRend->proto_frame_f_q, + &hDirACRend->proto_frame_f_q, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, - reference_power, - q_reference_power, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->hOutSetup.is_loudspeaker_setup, slot_idx, hSpatParamRendCom->num_freq_bands, hDirACRend->masa_stereo_type_detect, q_cldfb); - BREAK; + + proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); + IF(LT_16(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)){ + Scale_sig32(reference_power_fix + hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands), sub(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); + } ELSE { + Scale_sig32(reference_power_fix, hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q)); + DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); + } + temp_proto_frame_q = getScaleFactor32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len) -2; + Scale_sig32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q); + hDirACRend->proto_frame_f_q = add(hDirACRend->proto_frame_f_q, temp_proto_frame_q); + + BREAK; case 1: - protoSignalComputation1_fx( Cldfb_RealBuffer, Cldfb_ImagBuffer, + protoSignalComputation1_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->proto_frame_f_fx, - hDirACRend->proto_frame_f_q, + &hDirACRend->proto_frame_f_q, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, - hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, - reference_power, - q_reference_power, + &hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, + reference_power_fix, &DirAC_mem.reference_power_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, + &hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, slot_idx, hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands, q_cldfb); - BREAK; + + proto_direct_buffer_f_temp_q[slot_idx] = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; move16(); + + IF(LT_16(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)){ + Scale_sig32(reference_power_fix + hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands), sub(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); + } ELSE { + Scale_sig32(reference_power_fix, hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q)); + DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); + } + + temp_proto_frame_q = getScaleFactor32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len) - 2; + Scale_sig32(hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_len, temp_proto_frame_q); + hDirACRend->proto_frame_f_q = add(hDirACRend->proto_frame_f_q, temp_proto_frame_q); + + BREAK; default: return; } @@ -6081,7 +6141,6 @@ static void ivas_masa_ext_dirac_render_sf_fx( /*-----------------------------------------------------------------* * frequency domain decorrelation *-----------------------------------------------------------------*/ - IF ( EQ_16(hDirACRend->proto_signal_decorr_on, 1 )) { /* decorrelate prototype frame */ @@ -6092,22 +6151,26 @@ static void ivas_masa_ext_dirac_render_sf_fx( hDirACRend->num_protos_diff, hDirACRend->synthesisConf, nchan_transport, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + i_mult(i_mult(slot_idx, hSpatParamRendCom->num_freq_bands), shl( hDirACRend->num_outputs_diff, 1)), + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->num_protos_diff, hDirACRend->proto_index_diff, - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + add (i_mult(i_mult(slot_idx, hSpatParamRendCom->num_freq_bands), shl(hDirACRend->num_outputs_diff, 1)) , shl(i_mult(hSpatParamRendCom->num_freq_bands, s_min( 4, nchan_transport )), 1)), - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, - onset_filter, + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx + slot_idx * 2 * hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_diff + 2 * hSpatParamRendCom->num_freq_bands * min( 4, nchan_transport ), + &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, + onset_filter_fx, hDirACRend->h_freq_domain_decorr_ap_params, hDirACRend->h_freq_domain_decorr_ap_state ); - v_multc_fixed( onset_filter, ONE_IN_Q28, onset_filter, hSpatParamRendCom->num_freq_bands ); /*0.25 in Q31 = Q28*/ - v_add_fixed( onset_filter, onset_filter_subframe, onset_filter_subframe, hSpatParamRendCom->num_freq_bands, 1); - p_onset_filter = onset_filter_subframe; + Scale_sig32(onset_filter_fx, hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands, -1); + + v_multc_fixed( onset_filter_fx, ONE_IN_Q29, onset_filter_fx, hSpatParamRendCom->num_freq_bands ); /*0.25 in Q30 = Q28*/ + v_add_fixed( onset_filter_fx, onset_filter_subframe_fx, onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands, 1); + p_onset_filter_fx = onset_filter_subframe_fx; } ELSE { + set_zero_fx(DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f_len); + ivas_dirac_dec_decorr_process_fx( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, hDirACRend->num_protos_diff, @@ -6118,45 +6181,61 @@ static void ivas_masa_ext_dirac_render_sf_fx( hDirACRend->num_protos_diff, hDirACRend->proto_index_diff, DirAC_mem.frame_dec_f_fx, - DirAC_mem.frame_dec_f_q, - onset_filter, + &DirAC_mem.frame_dec_f_q, + onset_filter_fx, hDirACRend->h_freq_domain_decorr_ap_params, hDirACRend->h_freq_domain_decorr_ap_state ); - + + Scale_sig32(onset_filter_fx, hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands, -1); hDirACRend->proto_frame_dec_f_fx = DirAC_mem.frame_dec_f_fx; - p_onset_filter = onset_filter; + hDirACRend->proto_frame_dec_f_q = DirAC_mem.frame_dec_f_q; move16(); + p_onset_filter_fx = onset_filter_fx; } } ELSE { IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) { - set32_fx( onset_filter_subframe, MAX_32, hSpatParamRendCom->num_freq_bands ); - p_onset_filter = onset_filter_subframe; + set32_fx( onset_filter_subframe_fx, MAX_32, hSpatParamRendCom->num_freq_bands ); + p_onset_filter_fx = onset_filter_subframe_fx; } ELSE { /* no frequency domain decorrelation: use prototype frame */ hDirACRend->proto_frame_dec_f_fx = hDirACRend->proto_frame_f_fx; - p_onset_filter = NULL; + hDirACRend->proto_frame_dec_f_q = hDirACRend->proto_frame_f_q; + p_onset_filter_fx = NULL; } } /*-----------------------------------------------------------------* * output synthesis *-----------------------------------------------------------------*/ + test(); IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS) || EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD )) { /* Compute diffuse prototypes */ ivas_dirac_dec_compute_diffuse_proto_fx( hDirACRend, hSpatParamRendCom->num_freq_bands, slot_idx ); + } + Scale_sig32(h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, h_dirac_output_synthesis_state->diffuse_power_factor_q)); + h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); - ivas_dirac_dec_output_synthesis_process_slot( reference_power, - p_onset_filter, + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q)); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; move16(); + + /*Word16 q_cy_auto_diff_smooth = getScaleFactor32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len); + Scale_sig32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth);*/ + + ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fix, + DirAC_mem.reference_power_q, + p_onset_filter_fx, azimuth, elevation, hSpatParamRendCom->diffuseness_vector_fx[md_idx], + hSpatParamRendCom->q_diffuseness_vector, hSpatParamRendCom, hDirACRend, 0, @@ -6170,39 +6249,200 @@ static void ivas_masa_ext_dirac_render_sf_fx( IF ( NE_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) { - v_add_fixed( reference_power, reference_power_smooth, reference_power_smooth, hSpatParamRendCom->num_freq_bands, 1); + Scale_sig32(DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, -1); + DirAC_mem.reference_power_q = sub(DirAC_mem.reference_power_q, 1); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; + v_add_fixed( reference_power_fix, reference_power_smooth_fx, reference_power_smooth_fx, hSpatParamRendCom->num_freq_bands, 0); } } + /*Rescaling proto_direct_buffer_f*/ + Word16 temp = MAX_16; + + FOR(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++) + { + temp = s_min(temp, proto_direct_buffer_f_temp_q[slot_idx]); + } + + IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) + { + FOR(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++) + { + Scale_sig32(&hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[i_mult(slot_idx , idiv1616(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len , hSpatParamRendCom->subframe_nbslots[subframe_idx]))], idiv1616(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len , hSpatParamRendCom->subframe_nbslots[subframe_idx]), sub(temp, proto_direct_buffer_f_temp_q[slot_idx])); + } + } + ELSE + { + FOR(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++) + { + Scale_sig32(&hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx[i_mult(slot_idx , idiv1616(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len , hSpatParamRendCom->subframe_nbslots[subframe_idx]))], idiv1616(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len , hSpatParamRendCom->subframe_nbslots[subframe_idx]), sub(temp, proto_direct_buffer_f_temp_q[slot_idx])); + } + + } + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = temp; move16(); + ivas_dirac_dec_output_synthesis_get_interpolator_fx( &hDirACRend->h_output_synthesis_psd_params, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + /*Memories Scaling*/ + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q)); + hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q = Q31; move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q)); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q = Q31; move16(); + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.direct_responses_q)); + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q31; move16(); + IF ( EQ_16(hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD )) { - ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer, - Cldfb_ImagBuffer, + FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + Scale_sig32(Cldfb_RealBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub(6, q_cldfb)); + Scale_sig32(Cldfb_ImagBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub(6, q_cldfb)); + } + } + q_cldfb = 6; move16(); + + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, sub(26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth)); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth = Q26; move16(); + + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, sub(26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth)); + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = Q26; move16(); + + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len, sub(26, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev)); + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = Q26; move16(); + + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len, sub(26, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev)); + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = Q26; move16(); + + ivas_dirac_dec_output_synthesis_process_subframe_gain_shd_fx( Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, hSpatParamRendCom, hDirACRend, nchan_transport, hSpatParamRendCom->subframe_nbslots[subframe_idx], - p_onset_filter, - diffuseness_vector, - 0, + p_onset_filter_fx, + diffuseness_vector_fx, 0, + 0, &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, - &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev - ); + &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev); + q_cldfb = -2; move16(); + hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev; move16(); + hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev; move16(); } ELSE { - ivas_dirac_dec_output_synthesis_process_subframe_psd_ls( Cldfb_RealBuffer, - Cldfb_ImagBuffer, +#if 1 + IF( hDirACRend->proto_signal_decorr_on ) + { + //hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q; + + Word16 new_proto_diffuse_buffer_f_q = getScaleFactor32(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); + Word16 new_proto_direct_buffer_f_q = getScaleFactor32(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len); + + scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, new_proto_diffuse_buffer_f_q); + scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, new_proto_direct_buffer_f_q); + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = add(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, new_proto_direct_buffer_f_q); + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = add(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, new_proto_diffuse_buffer_f_q); + + /*scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q), hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q)); + scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q), hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q)); + hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q); + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q);*/ + } +#endif + /*Buffer Scaling*/ + FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + Scale_sig32(Cldfb_RealBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub(11, q_cldfb)); + Scale_sig32(Cldfb_ImagBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub(11, q_cldfb)); + } + } + q_cldfb = 11; move16(); + + + Word16 reference_power_temp_q = getScaleFactor32(DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len); + scale_sig32(DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, reference_power_temp_q); + DirAC_mem.reference_power_q = add(DirAC_mem.reference_power_q, reference_power_temp_q); + DirAC_mem.reference_power_smooth_q = add(DirAC_mem.reference_power_q, reference_power_temp_q); + + Word16 q_cy_auto_diff_smooth = getScaleFactor32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len); + Scale_sig32(h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->cy_auto_diff_smooth_len, q_cy_auto_diff_smooth); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add(h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, q_cy_auto_diff_smooth); + + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.direct_responses_square_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands, sub(31, hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q)); + hDirACRend->h_output_synthesis_psd_state.direct_responses_square_q = Q31; move16(); + Scale_sig32(h_dirac_output_synthesis_state->diffuse_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub(31, h_dirac_output_synthesis_state->diffuse_power_factor_q)); + h_dirac_output_synthesis_state->diffuse_power_factor_q = Q31; move16(); + Scale_sig32(h_dirac_output_synthesis_state->direct_responses_fx, hSpatParamRendCom->num_freq_bands, sub(31, h_dirac_output_synthesis_state->direct_responses_q)); + h_dirac_output_synthesis_state->direct_responses_q = Q31; move16(); + + /*Q-adjustment*/ + IF( hDirACRend->masa_stereo_type_detect ) + { + hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = L_shl(hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, sub(s_min(hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y),hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth)); + hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = L_shl(hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, sub(s_min(hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y),hDirACRend->masa_stereo_type_detect->q_subtract_power_y)); + + hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = s_min(hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y); + hDirACRend->masa_stereo_type_detect->q_subtract_power_y = s_min(hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y); + } + + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q),hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q)); + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q); + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q), hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q)); + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q); + + Word16 proto_power_diff_smooth_prev_temp_q = getScaleFactor32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len); + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, proto_power_diff_smooth_prev_temp_q); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = add(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, proto_power_diff_smooth_prev_temp_q); + + Word16 proto_power_diff_smooth_temp_q = getScaleFactor32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len); + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, proto_power_diff_smooth_temp_q); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, proto_power_diff_smooth_temp_q); + + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q),hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q)); + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q),hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q)); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q); + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = s_min(hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q); + + Scale_sig32(diffuseness_vector_fx, hSpatParamRendCom->num_freq_bands, 1); + + /*Buffer rescaling*/ + + Scale_sig32(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hSpatParamRendCom->num_freq_bands, sub(s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q),hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q)); + Scale_sig32(DirAC_mem.reference_power_fx, DirAC_mem.reference_power_len, sub(s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q),DirAC_mem.reference_power_q)); + + hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q); + DirAC_mem.reference_power_q = s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q); + DirAC_mem.reference_power_smooth_q = s_min(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, DirAC_mem.reference_power_q); + + ivas_dirac_dec_output_synthesis_process_subframe_psd_ls_fx( Cldfb_RealBuffer_fx, + Cldfb_ImagBuffer_fx, hSpatParamRendCom, hDirACRend, hSpatParamRendCom->subframe_nbslots[subframe_idx], - diffuseness_vector, - reference_power_smooth, - 1.0f, - 0 ); + diffuseness_vector_fx, + reference_power_smooth_fx, + &DirAC_mem.reference_power_smooth_q, + ONE_IN_Q31, + 0, &q_cldfb ); + + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q; + hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q = DirAC_mem.reference_power_smooth_q; + IF(LT_16(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)){ + Scale_sig32(reference_power_fix + hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_len, hSpatParamRendCom->num_freq_bands), sub(DirAC_mem.reference_power_q, DirAC_mem.reference_power_smooth_q)); + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q; move16(); + } ELSE { + Scale_sig32(reference_power_fix, hSpatParamRendCom->num_freq_bands, sub(DirAC_mem.reference_power_smooth_q, DirAC_mem.reference_power_q)); + DirAC_mem.reference_power_q = DirAC_mem.reference_power_smooth_q; move16(); + } } /*-----------------------------------------------------------------* @@ -6212,9 +6452,22 @@ static void ivas_masa_ext_dirac_render_sf_fx( index_slot = slot_idx_start_cldfb_synth; move16(); { - Word32 *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; - Word32 *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES]; Word16 outchannels; + Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; + Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES]; + + FOR( ch = 0; ch < hDirACRend->num_outputs_dir; ch++ ) + { + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + Scale_sig32(Cldfb_RealBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub(10, q_cldfb)); + Scale_sig32(Cldfb_ImagBuffer_fx[ch][slot_idx], + hSpatParamRendCom->num_freq_bands, sub(10, q_cldfb)); + } + } + q_cldfb = 10; move16(); + hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state = q_cldfb; move16(); idx_in = 0; move16(); idx_lfe = 0; move16(); @@ -6222,13 +6475,12 @@ static void ivas_masa_ext_dirac_render_sf_fx( outchannels = add(hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe); /* Note here that compared to decoder path, there is no separate channel ever for MASA ext rend path */ - FOR ( ch = 0; ch < outchannels; ch++ ) { IF ( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ) && ( EQ_16(hDirACRend->hOutSetup.index_lfe[idx_lfe], ch )) ) { /* No LFE for MASA rendering */ - set32_fx( &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); + set32_fx( &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), 0, hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->num_freq_bands ); IF ( LT_16(idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) )) { @@ -6238,15 +6490,18 @@ static void ivas_masa_ext_dirac_render_sf_fx( ELSE { /* open CLDFB buffer up to CLDFB_NO_CHANNELS_MAX bands for 48kHz */ + FOR ( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) { - RealBuffer[i] = Cldfb_RealBuffer[idx_in][i]; - ImagBuffer[i] = Cldfb_ImagBuffer[idx_in][i]; + RealBuffer_fx[i] = Cldfb_RealBuffer_fx[idx_in][i]; + ImagBuffer_fx[i] = Cldfb_ImagBuffer_fx[idx_in][i]; } - cldfbSynthesis_ivas_fx( RealBuffer, ImagBuffer, &( output_f[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], hMasaExtRend->cldfbSynRend[idx_in] ); + cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_f_fx[ch][index_slot * hSpatParamRendCom->num_freq_bands] ), hSpatParamRendCom->num_freq_bands * hSpatParamRendCom->subframe_nbslots[subframe_idx], hMasaExtRend->cldfbSynRend[idx_in] ); idx_in++; } } + + hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state = sub(q_cldfb, 1); } hSpatParamRendCom->slots_rendered = add(hSpatParamRendCom->subframe_nbslots[subframe_idx], hSpatParamRendCom->slots_rendered); hSpatParamRendCom->subframes_rendered++; @@ -6256,6 +6511,7 @@ static void ivas_masa_ext_dirac_render_sf_fx( return; } #endif +#ifndef IVAS_FLOAT_FIXED void ivas_masa_ext_dirac_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ float *output_f[], /* i/o: input/output signals in time domain */ @@ -6292,7 +6548,7 @@ void ivas_masa_ext_dirac_render( return; } -#ifdef IVAS_FLOAT_FIXED_u //Currently disabled +#else void ivas_masa_ext_dirac_render_fx( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ Word32 *output_f[], /* i/o: input/output signals in time domain */ @@ -6317,7 +6573,7 @@ void ivas_masa_ext_dirac_render_fx( FOR ( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ ) { - hSpatParamRendCom->slots_rendered = 0; + hSpatParamRendCom->slots_rendered = 0; move16(); ivas_masa_ext_dirac_render_sf_fx( hMasaExtRend, output_f_local ); FOR ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ ) { diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 491286d4cf34ac72776c720d64c3bc81298f40cf..ebb3e8c4b8b0d1b65005ea3f0384e24b5dee6899 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1057,19 +1057,19 @@ void ivas_dirac_deallocate_parameters( SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i/o: common data for spatial parametric rendering */ const int16_t params_flag /* i : set of parameters flag */ ); - +#ifndef IVAS_FLOAT_FIXED void ivas_masa_ext_dirac_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ float *output_f[], /* i/o: input/output signals in time domain */ const int16_t num_subframes /* i : number of subframes to render */ ); - +#else void ivas_masa_ext_dirac_render_fx( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ Word32 *output_f[], /* i/o: input/output signals in time domain */ const Word16 num_subframes /* i : number of subframes to render */ ); - +#endif /*----------------------------------------------------------------------------------* * HRTF *----------------------------------------------------------------------------------*/ diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 2f3ad8378bacf0bacbf2b7e6cb34b360a721833d..f469a5fe5941c44a1f15d89eb6f1e71df10cdc53 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -315,7 +315,10 @@ typedef struct dirac_dec_stack_mem #ifdef IVAS_FLOAT_FIXED Word32 *reference_power_fx; Word16 reference_power_q; + Word16 reference_power_smooth_q; + Word16 reference_power_len; Word32 *onset_filter_fx; + Word16 onset_filter_len; #endif } DIRAC_DEC_STACK_MEM, *DIRAC_DEC_STACK_MEM_HANDLE; @@ -411,17 +414,22 @@ typedef struct dirac_output_synthesis_state_structure 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_len; Word32 *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_smooth_prev_q; + Word16 proto_power_smooth_prev_len; Word32 *proto_power_diff_smooth_fx; Word32 *proto_power_diff_smooth_prev_fx; + Word16 proto_power_diff_smooth_prev_len; + Word16 proto_power_diff_smooth_prev_q; Word16 proto_power_diff_smooth_q; Word16 proto_power_diff_smooth_len; /* only pointer to local buffers */ 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; + Word16 proto_direct_buffer_f_len; 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; Word16 proto_diffuse_buffer_f_len; @@ -433,6 +441,9 @@ typedef struct dirac_output_synthesis_state_structure Word16 gains_dir_prev_q; Word16 gains_diff_prev_q; + Word16 gains_dir_prev_len; + Word16 gains_diff_prev_len; + /* only pointer to local buffers */ Word32 *cy_auto_dir_smooth_fx; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ Word32 *cy_cross_dir_smooth_fx; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ @@ -442,6 +453,10 @@ typedef struct dirac_output_synthesis_state_structure Word16 q_cy_cross_dir_smooth; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ Word16 q_cy_auto_diff_smooth; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + Word16 cy_auto_dir_smooth_len; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ + Word16 cy_cross_dir_smooth_len; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ + Word16 cy_auto_diff_smooth_len; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + /* PSD memories */ Word32 *cy_auto_dir_smooth_prev_fx; /* Target auto PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ Word32 *cy_cross_dir_smooth_prev_fx; /* Target cross PSD of direct sound of previous synthesis block. Size: num_freq_bands*num_channels. */ @@ -451,10 +466,15 @@ typedef struct dirac_output_synthesis_state_structure Word16 q_cy_cross_dir_smooth_prev; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ Word16 q_cy_auto_diff_smooth_prev; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + Word16 cy_auto_dir_smooth_prev_len; /* Target auto PSD of direct sound. Size: num_freq_bands*num_channels. */ + Word16 cy_cross_dir_smooth_prev_len; /* Target cross PSD of direct sound. Size: num_freq_bands*num_channels. */ + Word16 cy_auto_diff_smooth_prev_len; /* Target auto PSD of diffuse sound. Size: num_freq_bands*num_channels. */ + const Word32 *onset_filter_fx; /* Temporal smoothing memories */ Word32 *reference_power_smooth_prev_fx; + Word16 reference_power_smooth_prev_q; Word32 *direction_smoothness_prev_fx; // Q31 #endif diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index eb7a591bda5c4724ba3ac89a3bdec3b9b0026c40..aba41dfe46cc57b20d9ec40bb60b816d79d85348 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -371,7 +371,14 @@ struct IVAS_REND static ivas_error initMasaExtRenderer( input_masa *inputMasa, const AUDIO_CONFIG outConfig ); static void freeMasaExtRenderer( MASA_EXT_REND_HANDLE *hMasaExtRendOut ); - +#ifdef IVAS_FLOAT_FIXED //TOBE REMOVED +static void intermidiate_ext_dirac_render( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ + Word32 *output_f[], /* i/o: input/output signals in time domain */ + float *output_f_flt[], /* i/o: input/output signals in time domain */ + Word16 to_fix +); +#endif /*-------------------------------------------------------------------* * Local functions *-------------------------------------------------------------------*/ @@ -11671,7 +11678,7 @@ static ivas_error renderInputMasa( int16_t maxBin; float *tmpBuffer[MAX_OUTPUT_CHANNELS]; float tmpBuffer_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; -#ifndef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED Word32 *tmpBuffer_fx[MAX_OUTPUT_CHANNELS]; Word32 tmpBuffer_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; #endif @@ -11707,10 +11714,12 @@ static ivas_error renderInputMasa( { /* MASA prerendering path for MASA -> MASA */ renderMasaToMasa( masaInput, outAudio ); +#ifdef IVAS_FLOAT_FIXED for ( Word16 i = 0; i < outAudio.config.numChannels * outAudio.config.numSamplesPerChannel; i++ ) { outAudio.data[i] = (float) outAudio.data_fx[i] / ( 1 << *outAudio.pq_fact ); } +#endif } else { @@ -11720,7 +11729,7 @@ static ivas_error renderInputMasa( { tmpBuffer[ch] = tmpBuffer_buff[ch]; } -#ifndef IVAS_FLOAT_FIXED +#ifdef IVAS_FLOAT_FIXED for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) { tmpBuffer_fx[ch] = tmpBuffer_buff_fx[ch]; @@ -11734,13 +11743,32 @@ static ivas_error renderInputMasa( switch ( masaInput->hMasaExtRend->renderer_type ) { case RENDERER_DIRAC: +#ifdef IVAS_FLOAT_FIXED copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); +#else + copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); +#endif +#ifdef IVAS_FLOAT_FIXED +#if 1 //TOBE REMOVED + intermidiate_ext_dirac_render(masaInput->hMasaExtRend, tmpBuffer_fx, tmpBuffer, 1); +#endif + ivas_masa_ext_dirac_render_fx( masaInput->hMasaExtRend, tmpBuffer_fx, num_subframes ); + +#if 1 //TOBE REMOVED + intermidiate_ext_dirac_render(masaInput->hMasaExtRend, tmpBuffer_fx, tmpBuffer, 0); +#endif +#else ivas_masa_ext_dirac_render( masaInput->hMasaExtRend, tmpBuffer, num_subframes ); +#endif break; case RENDERER_STEREO_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC: case RENDERER_BINAURAL_PARAMETRIC_ROOM: +#ifdef IVAS_FLOAT_FIXED copyMasaMetadataToDiracRenderer_fx( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); +#else + copyMasaMetadataToDiracRenderer( &masaInput->masaMetadata, masaInput->hMasaExtRend->hSpatParamRendCom, maxBin ); +#endif ivas_masa_ext_rend_parambin_render( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer, num_subframes ); break; case RENDERER_DISABLE: @@ -12835,6 +12863,7 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } + hDirACRend->proto_frame_f_len = 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands; } @@ -12980,7 +13009,11 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } +#ifdef IVAS_FLOAT_FIXED + ivas_masa_init_stereotype_detection_fx( hDirACRend->masa_stereo_type_detect ); +#else ivas_masa_init_stereotype_detection( hDirACRend->masa_stereo_type_detect ); +#endif } else { @@ -13192,10 +13225,20 @@ static ivas_error ivas_masa_ext_rend_dirac_rend_init( if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) { +#ifdef IVAS_FLOAT_FIXED + hDirACRend->proto_frame_f_fx = NULL; +#endif hDirACRend->proto_frame_f = NULL; } else { +#ifdef IVAS_FLOAT_FIXED + IF ( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + hDirACRend->proto_frame_f_len = 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands; +#endif if ( ( hDirACRend->proto_frame_f = (float *) malloc( sizeof( float ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); @@ -13958,3 +14001,354 @@ static void freeMasaExtRenderer( return; } + +#ifdef IVAS_FLOAT_FIXED +static void intermidiate_ext_dirac_render( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA renderer structure */ + Word32 *output_f[], /* i/o: input/output signals in time domain */ + float *output_f_flt[], /* i/o: input/output signals in time domain */ + Word16 to_fix +) +{ + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; + DIRAC_DEC_STACK_MEM DirAC_mem; + int16_t i, ch, q_cldfb; + DIRAC_REND_HANDLE hDirACRend; + int16_t subframe_idx; + int16_t slot_idx; + int16_t nchan_transport; + int16_t masa_band_mapping[MASA_FREQUENCY_BANDS + 1]; + + hDirACRend = hMasaExtRend->hDirACRend; + hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; + nchan_transport = hMasaExtRend->nchan_input; + DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; + + h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); + + subframe_idx = hSpatParamRendCom->subframes_rendered; + + DirAC_mem = hDirACRend->stack_mem; + + if(to_fix) + { + DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q = Q31; + floatToFixed_arrL(hDirACRend->stack_mem.onset_filter, hDirACRend->stack_mem.onset_filter_fx, Q30, hDirACRend->stack_mem.onset_filter_len ); + q_cldfb = 11; + for(i = 0; i < MAX_OUTPUT_CHANNELS; i++) + { + floatToFixed_arrL(output_f_flt[i], output_f[i], q_cldfb, L_FRAME48k); + } + + for(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++){ + for ( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + hSpatParamRendCom->diffuseness_vector_fx[hSpatParamRendCom->render_to_md_map[slot_idx]][i] = floatToFixed( hSpatParamRendCom->diffuseness_vector[hSpatParamRendCom->render_to_md_map[slot_idx]][i], Q30 ); + floatToFixed_arr(hSpatParamRendCom->surroundingCoherence[slot_idx], hSpatParamRendCom->surroundingCoherence_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + } + } + for(slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++){ + 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_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + floatToFixed_arr(hSpatParamRendCom->spreadCoherence[slot_idx], hSpatParamRendCom->spreadCoherence_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arr(hSpatParamRendCom->spreadCoherence2[slot_idx], hSpatParamRendCom->spreadCoherence2_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, Q15, hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + else + { + if(hDirACRend->panningConf == DIRAC_PANNING_HOA3) + { + if (masa_band_mapping == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) + { + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + } + else if (((hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD) && (masa_band_mapping != NULL)) || + hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO) + { + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + floatToFixed_arr(hSpatParamRendCom->spreadCoherence[slot_idx], hSpatParamRendCom->spreadCoherence_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arr(hSpatParamRendCom->spreadCoherence2[slot_idx], hSpatParamRendCom->spreadCoherence2_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, Q15, hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ + { + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + floatToFixed_arr(hSpatParamRendCom->spreadCoherence[slot_idx], hSpatParamRendCom->spreadCoherence_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arr(hSpatParamRendCom->spreadCoherence2[slot_idx], hSpatParamRendCom->spreadCoherence2_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, Q15, hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + + } + else if (hDirACRend->panningConf == DIRAC_PANNING_VBAP) /*VBAP*/ + { + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = 30; + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.direct_responses, hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, hDirACRend->h_output_synthesis_psd_state.direct_responses_q, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ) ); + floatToFixed_arr(hSpatParamRendCom->spreadCoherence[slot_idx], hSpatParamRendCom->spreadCoherence_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arr(hSpatParamRendCom->spreadCoherence2[slot_idx], hSpatParamRendCom->spreadCoherence2_fx[slot_idx], Q15, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arr( hDirACRend->diffuse_response_function, hDirACRend->diffuse_response_function_fx, Q15, hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio1[slot_idx], hSpatParamRendCom->energy_ratio1_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hSpatParamRendCom->energy_ratio2[slot_idx], hSpatParamRendCom->energy_ratio2_fx[slot_idx], Q30, hSpatParamRendCom->num_freq_bands ); + } + } + } + if(h_dirac_output_synthesis_state->diffuse_responses_square_fx){ + h_dirac_output_synthesis_state->diffuse_responses_square_q = Q31; + floatToFixed_arrL( h_dirac_output_synthesis_state->diffuse_responses_square, h_dirac_output_synthesis_state->diffuse_responses_square_fx, h_dirac_output_synthesis_state->diffuse_responses_square_q, hDirACRend->num_outputs_dir ); + } + + if(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth){ + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = L_get_q_buf1(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); + } + + if(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev){ + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = L_get_q_buf1(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len);; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth){ + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); + } + Word16 num_channels_dir = hDirACRend->num_outputs_dir; + + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + { + num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; + } + if(h_dirac_output_synthesis_state->cy_auto_diff_smooth){ + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = L_get_q_buf( h_dirac_output_synthesis_state->cy_auto_diff_smooth, num_channels_dir * hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( h_dirac_output_synthesis_state->cy_auto_diff_smooth, h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); + } + + if(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev){ + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = L_get_q_buf1(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len);; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); + } + + hDirACRend->h_output_synthesis_psd_params.diffuse_compensation_factor_fx = floatToFixed( hDirACRend->h_output_synthesis_psd_params.diffuse_compensation_factor, Q27 ); // Q27 + + hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; + hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len ); + if(hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev){ + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); + } + + IF( hDirACRend->masa_stereo_type_detect ) + { + IF( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db == -INFINITY ) + { + hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = MIN_32; + } + ELSE + { + hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx = floatToFixed( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db, Q21 ); + } + } + + floatToFixed_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len ); + if ( hDirACRend->proto_signal_decorr_on == 1 ) + { + Word16 tmp_e; + f2me_buf(hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, &tmp_e, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); + hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = 31 - tmp_e; + } + + f2me_buf(hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, &hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = 31 - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q; + + if( hDirACRend->masa_stereo_type_detect != NULL ) + { + hDirACRend->masa_stereo_type_detect->q_target_power_y_smooth = L_get_q( hDirACRend->masa_stereo_type_detect->target_power_y_smooth ); + hDirACRend->masa_stereo_type_detect->target_power_y_smooth_fx = floatToFixed( hDirACRend->masa_stereo_type_detect->target_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_target_power_y_smooth ); + + hDirACRend->masa_stereo_type_detect->q_subtract_power_y = L_get_q(hDirACRend->masa_stereo_type_detect->subtract_power_y); + + hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth = L_get_q(hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth); + + hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx = floatToFixed( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth, hDirACRend->masa_stereo_type_detect->q_subtract_power_y_smooth ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = floatToFixed( hDirACRend->masa_stereo_type_detect->subtract_power_y, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); + } + //floatToFixed_arrL32( hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f_q, hDirACRend->proto_frame_f_len ); + + FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) + { + /* CLDFB Analysis*/ + FOR ( ch = 0; ch < nchan_transport; ch++ ) + { + q_cldfb = 11; + hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = q_cldfb; + + /*for (i = 0; i < CLDFB_NO_CHANNELS_MAX; i++) { + output_f_fx[ch][hSpatParamRendCom->num_freq_bands * index_slot + i] = (Word32)(output_f[ch][hSpatParamRendCom->num_freq_bands * index_slot + i] * (1 << q_cldfb)); + }*/ + for (i = 0; i < hMasaExtRend->cldfbAnaRend[ch]->p_filter_length - hMasaExtRend->cldfbAnaRend[ch]->no_channels; i++) { + hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx[i] = (Word32)(hMasaExtRend->cldfbAnaRend[ch]->cldfb_state[i] * (1 << (hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state))); + } + } + } + floatToFixed_arrL32( hDirACRend->hoa_encoder, hDirACRend->hoa_encoder_fx, Q29, hDirACRend->hoa_encoder_len ); + if(DirAC_mem.frame_dec_f) + { + //f2me_buf(DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_fx, &hDirACRend->proto_frame_dec_f_q, DirAC_mem.frame_dec_f_len); + } + hDirACRend->proto_frame_dec_f_q = 31 - hDirACRend->proto_frame_dec_f_q; + if(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth){ + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len ); + } + + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); + + if( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev != 0 ) + { + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q = L_get_q_buf1( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); + floatToFixed_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); + } + + for ( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) + { + q_cldfb = 11; + hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = q_cldfb; + for (i = 0; i < hMasaExtRend->cldfbSynRend[ch]->p_filter_length; i++) { + hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx[i] = (Word32)(hMasaExtRend->cldfbSynRend[ch]->cldfb_state[i] * (1 << (hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state - 1))); + } + } + } + else + { + FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) + { + hDirACRend->h_output_synthesis_psd_state.direct_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_q ); + hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor[i] = fix_to_float( hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_fx[i], hDirACRend->h_output_synthesis_psd_state.diffuse_power_factor_q); + } + IF(EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) + { + fixedToFloat_arrL( 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 ) ); + } + ELSE + { + fixedToFloat_arrL( 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_arrL( 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 ) ); + } + } + + fixedToFloat_arr( hDirACRend->h_output_synthesis_psd_params.interpolator_fx, hDirACRend->h_output_synthesis_psd_params.interpolator, Q15, hSpatParamRendCom->subframe_nbslots[subframe_idx] ); + fixedToFloat_arrL(hDirACRend->stack_mem.onset_filter_fx, hDirACRend->stack_mem.onset_filter, Q30, hDirACRend->stack_mem.onset_filter_len ); + if(DirAC_mem.reference_power) + { + fixedToFloat_arrL(DirAC_mem.reference_power_fx, DirAC_mem.reference_power, DirAC_mem.reference_power_q, DirAC_mem.reference_power_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len); + } + if(hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.gains_dir_prev){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.gains_diff_prev){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len ); + } + if(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len ); + } + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_len); + if ( hDirACRend->proto_signal_decorr_on == 1 ) + { + fixedToFloat_arrL32(hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len); + if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) + { + fixedToFloat_arrL(hDirACRend->h_freq_domain_decorr_ap_state->direct_energy_smooth_fx, hDirACRend->h_freq_domain_decorr_ap_state->direct_energy_smooth, hDirACRend->h_freq_domain_decorr_ap_state->q_direct_energy_smooth, hDirACRend->num_protos_diff * hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr); + fixedToFloat_arrL(hDirACRend->h_freq_domain_decorr_ap_state->reverb_energy_smooth_fx, hDirACRend->h_freq_domain_decorr_ap_state->reverb_energy_smooth, hDirACRend->h_freq_domain_decorr_ap_state->q_reverb_energy_smooth, hDirACRend->num_protos_diff * hDirACRend->h_freq_domain_decorr_ap_params->max_band_decorr); + } + } + fixedToFloat_arrL32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len); + IF( hDirACRend->masa_stereo_type_detect != NULL ) + { + hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_target_ratio_db_fx, Q21 ); + + hDirACRend->masa_stereo_type_detect->target_power_y_smooth = fixedToFloat( hDirACRend->masa_stereo_type_detect->target_power_y_smooth_fx, hDirACRend->masa_stereo_type_detect->q_target_power_y_smooth ); + hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_power_y_smooth_fx, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); + hDirACRend->masa_stereo_type_detect->subtract_power_y = fixedToFloat( hDirACRend->masa_stereo_type_detect->subtract_power_y_fx, hDirACRend->masa_stereo_type_detect->q_subtract_power_y ); + } + fixedToFloat_arrL32( hDirACRend->proto_frame_f_fx, hDirACRend->proto_frame_f, hDirACRend->proto_frame_f_q, hDirACRend->proto_frame_f_len ); + //fixedToFloat_arrL32(DirAC_mem.frame_dec_f_fx, DirAC_mem.frame_dec_f, DirAC_mem.frame_dec_f_q, DirAC_mem.frame_dec_f_len); + + FOR ( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[hSpatParamRendCom->subframes_rendered]; slot_idx++ ) + { + //q_cldfb = 11; + //hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = q_cldfb; + /* CLDFB Analysis*/ + FOR ( ch = 0; ch < nchan_transport; ch++ ) + { + for (i = 0; i < hMasaExtRend->cldfbAnaRend[ch]->p_filter_length - hMasaExtRend->cldfbAnaRend[ch]->no_channels; i++) { + hMasaExtRend->cldfbAnaRend[ch]->cldfb_state[i] = (float)(hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx[i] / (1 << (hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state))); + } + } + } + if(hDirACRend->h_output_synthesis_psd_state.proto_power_smooth){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len ); + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_len ); + } + IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev != 0 ) + { + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_len ); + } + + for ( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) + { + for (i = 0; i < hMasaExtRend->cldfbSynRend[ch]->p_filter_length; i++) + { + hMasaExtRend->cldfbSynRend[ch]->cldfb_state[i] = ((float)hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx[i] / (1 << ((hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state)))); + } + } + if(hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx){ + fixedToFloat_arrL( hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev, hDirACRend->h_output_synthesis_psd_state.reference_power_smooth_prev_q, hSpatParamRendCom->num_freq_bands ); + } + for(i = 0; i < MAX_OUTPUT_CHANNELS; i++) + { + fixedToFloat_arrL(output_f[i], output_f_flt[i], hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state, L_FRAME48k); + } + } + +} +#endif \ No newline at end of file