From 5d525f2cf0ca302ad70622595089b555f6cd768a Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 1 Aug 2024 12:38:58 +0530 Subject: [PATCH] Conversion and cleanup of renderactiveinputsmasa, LTV crash fix and high MLD fixes [x] Fix for few LTV crash issue [ltv-SBA at 13.2 kbps, 32kHz in, 32kHz out, STEREO out] [x] MSAN fixes [x] Fix for high MLD issues --- lib_dec/acelp_core_switch_dec_fx.c | 4 +- lib_dec/dec_tcx_fx.c | 2 +- lib_dec/er_dec_tcx_fx.c | 1 + lib_dec/igf_dec_fx.c | 12 +- lib_dec/ivas_cpe_dec_fx.c | 2 +- lib_dec/ivas_mct_dec.c | 9 +- lib_dec/ivas_mdct_core_dec.c | 2 +- lib_enc/init_enc.c | 3 + lib_enc/ivas_stereo_classifier.c | 1 - lib_enc/ivas_stereo_dft_enc_itd.c | 1 - lib_enc/ivas_stereo_mdct_core_enc.c | 4 + lib_enc/tcx_utils_enc.c | 1 + lib_rend/ivas_dirac_dec_binaural_functions.c | 98 ++++-- lib_rend/ivas_prot_rend.h | 8 + lib_rend/lib_rend.c | 331 +++++++++---------- 15 files changed, 265 insertions(+), 214 deletions(-) diff --git a/lib_dec/acelp_core_switch_dec_fx.c b/lib_dec/acelp_core_switch_dec_fx.c index d2a81d11b..415d5fac0 100644 --- a/lib_dec/acelp_core_switch_dec_fx.c +++ b/lib_dec/acelp_core_switch_dec_fx.c @@ -848,9 +848,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx( st_fx->cldfbSyn->Q_cldfb_state = sub( st_fx->cldfbSyn->Q_cldfb_state, 1 ); Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 ); - /* output to Q0 */ - Copy_Scale_sig32_16( syn32, synth_out, L_FRAME16k, -5 ); - // Scale_sig(synth_out,L_FRAME48k, negate(st_fx->Q_syn)); + Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); cldfb_restore_memory_ivas_fx( st_fx->cldfbSyn ); diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 485308d6c..6df017afd 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -3299,7 +3299,7 @@ void IMDCT_ivas_fx( FOR( ; i < tcx_mdct_window_half_length; i++ ) { xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = mult_r( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.re ); - xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); + xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )] = add_sat( xn_buf_fx[sub( add( i, shr( overlap, 1 ) ), tcx_offset )], mult_r( mult_r( hTcxDec->syn_OverlFB[i], tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ), tcx_mdct_window_half_fx[sub( tcx_mdct_window_half_length, add( 1, i ) )].v.im ) ); move16(); move16(); } diff --git a/lib_dec/er_dec_tcx_fx.c b/lib_dec/er_dec_tcx_fx.c index a4102230e..1998a3f8f 100644 --- a/lib_dec/er_dec_tcx_fx.c +++ b/lib_dec/er_dec_tcx_fx.c @@ -1943,6 +1943,7 @@ void con_tcx_ivas_fx( new_Q = sub( Q_exc, 3 ); new_Q = s_max( new_Q, -1 ); + new_Q = s_min( new_Q, norm_s( tmp_deemph ) ); tmp16 = s_min( new_Q, st->prev_Q_syn ); st->prev_Q_syn = new_Q; diff --git a/lib_dec/igf_dec_fx.c b/lib_dec/igf_dec_fx.c index c2acb5be5..daf14cc1a 100644 --- a/lib_dec/igf_dec_fx.c +++ b/lib_dec/igf_dec_fx.c @@ -282,9 +282,12 @@ static void IGF_replaceTCXNoise_2_new_ivas( Word32 *in, /**< in IF( TCXNoise[sb] ) { Word16 nrm = norm_l( in[sb] ); - in[sb] = L_shl( in[sb], nrm ); // exp: 31 - tmp - in[sb] = Mpy_32_16_1( in[sb], g ); // exp: 31 - tmp + tmp_e - in[sb] = L_shr( in[sb], sub( in_e, sub( add( 31, tmp_e ), nrm ) ) ); // Making the exponent same as original + in[sb] = L_shl( in[sb], nrm ); // exp: 31 - tmp + move32(); + in[sb] = Mpy_32_16_1( in[sb], g ); // exp: 31 - tmp + tmp_e + move32(); + /* To handle corner cases */ + in[sb] = L_shr_sat( in[sb], sub( in_e, sub( add( 31, tmp_e ), nrm ) ) ); // Making the exponent same as original move32(); } } @@ -4017,6 +4020,9 @@ void IGFDecSetMode_ivas_fx( hIGFDec->flag_sparse = &hIGFDec->flag_sparseBuf[0]; hIGFDec->infoTCXNoise_ptr = &hIGFDec->infoTCXNoise_evs[0]; + hIGFDec->virtualSpec_fx = &hIGFDec->virtualSpec[0]; + hIGFDec->igfData.pSpecFlat = &hIGFDec->igfData.pSpecFlatBuf_fx[0]; + hIGFDec->igfData.igfInfo.nfSeed = &hIGFDec->igfData.igfInfo.nfSeedBuf[0]; return; } /**********************************************************************/ /* diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 59969dba2..832a0406b 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -138,7 +138,7 @@ ivas_error ivas_cpe_dec_fx( } q_old_out_LB = Q11; move16(); - FOR( Word16 ind1 = 0; ind1 < 1; ind1++ ) + FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 34ab57de5..50b54e70a 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -581,6 +581,7 @@ ivas_error ivas_mct_dec_fx( IF( hCPE->hCoreCoder[n]->Q_syn != 0 ) { Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); + Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_LB_fx, L_FRAME32k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); } IF( hCPE->hCoreCoder[n]->hBPF ) { @@ -591,10 +592,10 @@ ivas_error ivas_mct_dec_fx( { // Scale_sig(hCPE->hCoreCoder[n]->hTcxDec->synth_history_fx, NS2SA(hCPE->hCoreCoder[n]->output_Fs, PH_ECU_MEM_NS), negate(hCPE->hCoreCoder[n]->Q_syn)); } - IF( hCPE->hCoreCoder[n]->hHQ_core ) - { - Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); - } + // IF( hCPE->hCoreCoder[n]->hHQ_core ) + //{ + // Scale_sig( hCPE->hCoreCoder[n]->hHQ_core->old_out_fx, L_FRAME48k, negate( hCPE->hCoreCoder[n]->Q_syn ) ); + // } } diff --git a/lib_dec/ivas_mdct_core_dec.c b/lib_dec/ivas_mdct_core_dec.c index 36c68e3cf..e8c854128 100644 --- a/lib_dec/ivas_mdct_core_dec.c +++ b/lib_dec/ivas_mdct_core_dec.c @@ -2123,7 +2123,7 @@ void ivas_mdct_core_reconstruct_fx( /* PLC: [TCX: TD PLC] */ IF( MCT_flag != 0 ) { - con_tcx_fx( st, &synthFB_fx[0] /*, -1.f, NULL, 0, NULL */ ); + con_tcx_ivas_fx( st, &synthFB_fx[0], -16384, NULL, 0, NULL ); } ELSE { diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index 3a9cf28d4..a99092fdd 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -801,6 +801,9 @@ ivas_error init_encoder( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for hTcxEnc\n" ) ); } +#ifdef MSAN_FIX + set_f( st->hTcxEnc->spectrum_long, 0, N_MAX ); +#endif // MSAN_FIX /* Share the memories for 2xTCX10/4xTCX5 and for TCX20 */ #ifdef IVAS_FLOAT_FIXED diff --git a/lib_enc/ivas_stereo_classifier.c b/lib_enc/ivas_stereo_classifier.c index 89525e8ef..22d07cf28 100644 --- a/lib_enc/ivas_stereo_classifier.c +++ b/lib_enc/ivas_stereo_classifier.c @@ -969,7 +969,6 @@ void xtalk_classifier_dft( /* raw score */ hStereoClassif->xtalk_score = score; - printf( "%f ", hStereoClassif->xtalk_score ); if ( !hStereoClassif->vad_flag_glob ) { diff --git a/lib_enc/ivas_stereo_dft_enc_itd.c b/lib_enc/ivas_stereo_dft_enc_itd.c index 0f4c863a8..e01e9b5ba 100644 --- a/lib_enc/ivas_stereo_dft_enc_itd.c +++ b/lib_enc/ivas_stereo_dft_enc_itd.c @@ -1201,7 +1201,6 @@ void stereo_dft_enc_compute_itd( hItd->itd_cnt = 0; hItd->lp_phat_peak = 0.0f; } - printf( "\n%d %f ", itd, hItd->itd_thres ); { /* stereo Xtalk classifier */ diff --git a/lib_enc/ivas_stereo_mdct_core_enc.c b/lib_enc/ivas_stereo_mdct_core_enc.c index 93630057c..dd5f2d59f 100644 --- a/lib_enc/ivas_stereo_mdct_core_enc.c +++ b/lib_enc/ivas_stereo_mdct_core_enc.c @@ -127,7 +127,11 @@ void stereo_mdct_core_enc( Word32 *orig_spectrum_fx[CPE_CHANNELS][NB_DIV]; /* Pointers to MDCT output for a short block (L/R) */ Word32 powerSpec_fx[CPE_CHANNELS][N_MAX]; Word32 *p_powerSpec_fx[CPE_CHANNELS]; +#ifdef MSAN_FIX /*To be removed later*/ + Word32 powerSpecMsInv_long_fx[CPE_CHANNELS][N_MAX] = { 0 }; /* MS inv power spectrum, also inverse MDST spectrum */ +#else Word32 powerSpecMsInv_long_fx[CPE_CHANNELS][N_MAX]; /* MS inv power spectrum, also inverse MDST spectrum */ +#endif // MSAN_FIX Word32 *powerSpecMsInv_fx[CPE_CHANNELS][NB_DIV]; Word32 quantized_spectrum_long_fx[CPE_CHANNELS][N_MAX]; /* quantized MDCT spectrum, inv ms mask mdst spectrum, scratch for MS spectra in the MS decision */ Word32 *quantized_spectrum_fx[CPE_CHANNELS][NB_DIV]; diff --git a/lib_enc/tcx_utils_enc.c b/lib_enc/tcx_utils_enc.c index 5d844ba5b..50690669b 100644 --- a/lib_enc/tcx_utils_enc.c +++ b/lib_enc/tcx_utils_enc.c @@ -1686,6 +1686,7 @@ void ProcessStereoIGF_fx( hPrivateData->igfPastSFM_fx[i][j] = float_to_fix16( hPrivateData->igfPastSFM[i][j], 13 ); } } + floatToFixed_arr16( &hGrid->whiteningThreshold_flt[0][0], &hGrid->whiteningThreshold[0][0], Q13, 2 * IGF_MAX_TILES ); } #endif /**********************************flt to fix ends here*******************************************************/ IGFEncApplyStereo_fx( hStereoMdct, ms_mask, hIGFEnc, igfGridIdx, sts, pPowerSpectrum_fx, pPowerSpectrumMsInv_fx, inv_spectrum_fx, frameno, sp_aud_decision0, element_brate, mct_on ); diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index 590704a99..09c8f2a87 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -178,9 +178,11 @@ static void matrixMul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Ai static void matrixTransp2Mul( float Are[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Aim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bre[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float Bim[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outRe[BINAURAL_CHANNELS][BINAURAL_CHANNELS], float outIm[BINAURAL_CHANNELS][BINAURAL_CHANNELS] ); #endif - +#ifdef IVAS_FLOAT_FIXED +static void ivas_masa_ext_rend_parambin_internal_fx( MASA_EXT_REND_HANDLE hMasaExtRend, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, Word32 *output_fx[], const Word16 subframe ); +#else static void ivas_masa_ext_rend_parambin_internal( MASA_EXT_REND_HANDLE hMasaExtRend, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, float *output_f[], const int16_t subframe ); - +#endif #ifdef IVAS_FLOAT_FIXED static void formulate2x2MixingMatrix_fx( Word32 Ein1_fx, Word32 Ein2_fx, Word16 q_Ein, Word32 CinRe_fx, Word32 CinIm_fx, Word16 q_Cin, Word32 Eout1_fx, Word32 Eout2_fx, Word16 q_Eout, Word32 CoutRe_fx, Word32 CoutIm_fx, Word16 q_Cout, Word32 Q_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word32 Mre_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word32 Mim_fx[BINAURAL_CHANNELS][BINAURAL_CHANNELS], Word16 *q_M, const Word16 regularizationFactor_fx ); @@ -7812,10 +7814,10 @@ static void ivas_masa_ext_rend_parambin_internal( return; } #else -static void ivas_masa_ext_rend_parambin_internal( +static void ivas_masa_ext_rend_parambin_internal_fx( MASA_EXT_REND_HANDLE hMasaExtRend, COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, - float *output_f[], + Word32 *output_fx[], /* Q11*/ const Word16 subframe ) { @@ -7828,21 +7830,20 @@ static void ivas_masa_ext_rend_parambin_internal( Word16 i, j; Word16 nchan_transport; Word16 q_mat; - -#if 1 hDiracDecBin = hMasaExtRend->hDiracDecBin; hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; - Word32 *output_fx[MAX_OUTPUT_CHANNELS]; - Word32 output_fx_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; - FOR( ch = 0; ch < 2; ch++ ) - { - output_fx[ch] = output_fx_buff[ch]; - floatToFixed_arrL32( output_f[ch], output_fx[ch], Q11, L_FRAME48k ); - } -#endif Word32 Cldfb_RealBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_in_fx[6][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; + + FOR( i = 0; i < 6; i++ ) + { + FOR( j = 0; j < CLDFB_SLOTS_PER_SUBFRAME; j++ ) + { + set32_fx( Cldfb_RealBuffer_in_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + set32_fx( Cldfb_ImagBuffer_in_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + } Word32 Rmat_fx[3][3]; hDiracDecBin = hMasaExtRend->hDiracDecBin; @@ -7863,8 +7864,16 @@ static void ivas_masa_ext_rend_parambin_internal( move16(); config_data.qualityBasedSmFactor_fx = ONE_IN_Q31; move32(); - config_data.processReverb = hMasaExtRend->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ? 1 : 0; - move16(); + IF( EQ_16( hMasaExtRend->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) + { + config_data.processReverb = 1; + move16(); + } + ELSE + { + config_data.processReverb = 0; + move16(); + } config_data.ism_mode = ISM_MODE_NONE; move32(); @@ -7926,6 +7935,7 @@ static void ivas_masa_ext_rend_parambin_internal( } } Word16 q_inp = Q6; + move16(); IF( hCombinedOrientationData ) { FOR( i = 0; i < 3; i++ ) @@ -7982,20 +7992,15 @@ static void ivas_masa_ext_rend_parambin_internal( hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] > 0, 0, NULL ); -#if 1 Word16 q_out; q_inp = Q6; move16(); - FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) - { - output_fx[ch] = output_fx_buff[ch]; - } + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; move16(); } -#endif // Float to fix ends q_mat = hDiracDecBin->q_processMtx; move16(); @@ -8042,20 +8047,18 @@ static void ivas_masa_ext_rend_parambin_internal( move16(); move16(); -#if 1 // Fix to float FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { - fixedToFloat_arrL32( output_fx[ch], output_f[ch], q_out, nBins * hSpatParamRendCom->subframe_nbslots[subframe] ); + scale_sig32( output_fx[ch], nBins * hSpatParamRendCom->subframe_nbslots[subframe], sub( Q11, q_out ) ); scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state ) ); hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; } -#endif return; } #endif - +#ifndef IVAS_FLOAT_FIXED void ivas_masa_ext_rend_parambin_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ @@ -8095,3 +8098,46 @@ void ivas_masa_ext_rend_parambin_render( return; } +#else +void ivas_masa_ext_rend_parambin_render_fx( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output Q11*/ + const Word16 num_subframes ) /* i : number of subframes to render */ +{ + Word16 subframe; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + Word32 *p_output[BINAURAL_CHANNELS]; + Word16 ch; + + hSpatParamRendCom = hMasaExtRend->hSpatParamRendCom; + + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + p_output[ch] = output_f[ch]; + } + + hSpatParamRendCom->subframes_rendered = hSpatParamRendCom->dirac_read_idx; + move16(); + FOR( subframe = 0; subframe < num_subframes; subframe++ ) + { + Word16 n_samples_sf = i_mult( hSpatParamRendCom->slot_size, CLDFB_SLOTS_PER_SUBFRAME ); + hSpatParamRendCom->slots_rendered = 0; + move16(); + + ivas_masa_ext_rend_parambin_internal_fx( hMasaExtRend, hCombinedOrientationData, p_output, hSpatParamRendCom->dirac_read_idx ); + + FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + p_output[ch] += n_samples_sf; + } + + ivas_combined_orientation_update_index( hCombinedOrientationData, n_samples_sf ); + + hSpatParamRendCom->dirac_read_idx = ( add( hSpatParamRendCom->dirac_read_idx, 1 ) ) % hSpatParamRendCom->dirac_md_buffer_length; + move16(); + } + + return; +} +#endif diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index dc331271f..78ee3d424 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -357,12 +357,20 @@ void ivas_dirac_dec_binaural_render_fx( Word32 *output_f[] /* o : rendered time signal */ ); #endif +#ifndef IVAS_FLOAT_FIXED void ivas_masa_ext_rend_parambin_render( MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ float *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output */ const int16_t num_subframes /* i : number of subframes to render */ ); +#else +void ivas_masa_ext_rend_parambin_render_fx( + MASA_EXT_REND_HANDLE hMasaExtRend, /* i/o: MASA ext rend structure */ + COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined orientation handle */ + Word32 *output_f[], /* i/o: synthesized core-coder transport channels/DirAC output Q11*/ + const Word16 num_subframes ); /* i : number of subframes to render */ +#endif #ifndef IVAS_FLOAT_FIXED ivas_error ivas_dirac_dec_init_binaural_data( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 45d03afd3..d51e11142 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -130,8 +130,11 @@ typedef struct AUDIO_CONFIG inConfig; IVAS_REND_InputId id; IVAS_REND_AudioBuffer inputBuffer; - float gain; /* Linear, not in dB */ +#ifndef IVAS_FLOAT_FIXED + float gain; /* Linear, not in dB */ +#else Word32 gain_fx; /* Linear, not in dB */ +#endif rendering_context ctx; Word32 numNewSamplesPerChannel; /* Used to keep track how much new audio was fed before rendering current frame */ } input_base; @@ -384,8 +387,6 @@ 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 /*-------------------------------------------------------------------* @@ -572,7 +573,7 @@ static void copyBufferTo2dArray_fx( return; } -#endif +#else static void copyBufferTo2dArray( const IVAS_REND_AudioBuffer buffer, float array[][L_FRAME48k] ) @@ -593,6 +594,7 @@ static void copyBufferTo2dArray( return; } +#endif #ifdef IVAS_FLOAT_FIXED static void accumulate2dArrayToBuffer_fx( Word32 array[][L_FRAME48k], @@ -614,7 +616,7 @@ static void accumulate2dArrayToBuffer_fx( return; } -#endif +#else static void accumulate2dArrayToBuffer( float array[][L_FRAME48k], IVAS_REND_AudioBuffer *buffer ) @@ -633,6 +635,7 @@ static void accumulate2dArrayToBuffer( return; } +#endif #ifdef IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * limitRendererOutput() @@ -2156,7 +2159,7 @@ static void initRendInputBase_fx( return; } -#endif +#else static void initRendInputBase( input_base *inputBase, const AUDIO_CONFIG inConfig, @@ -2181,7 +2184,7 @@ static void initRendInputBase( return; } - +#endif #ifdef IVAS_FLOAT_FIXED static IVAS_ISM_METADATA defaultObjectPosition( @@ -5338,7 +5341,7 @@ static void clearInputMasa( freeMasaExtRenderer( &inputMasa->hMasaExtRend ); - initRendInputBase( &inputMasa->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); + initRendInputBase_fx( &inputMasa->base, IVAS_AUDIO_CONFIG_INVALID, 0, rendCtx, NULL, 0 ); return; } @@ -5500,7 +5503,7 @@ ivas_error IVAS_REND_Open( FOR( i = 0; i < RENDERER_MAX_MASA_INPUTS; ++i ) { - initRendInputBase( &hIvasRend->inputsMasa[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); + initRendInputBase_fx( &hIvasRend->inputsMasa[i].base, IVAS_AUDIO_CONFIG_INVALID, 0, getRendCtx( hIvasRend ), NULL, 0 ); hIvasRend->inputsMasa[i].metadataHasBeenFed = false; hIvasRend->inputsMasa[i].bufferData = NULL; @@ -12587,14 +12590,11 @@ static ivas_error renderInputMasa( IVAS_REND_AudioBuffer outAudio ) { IVAS_REND_AudioBuffer inAudio; - int16_t ch; - int16_t maxBin; - float *tmpBuffer[MAX_OUTPUT_CHANNELS]; - float tmpBuffer_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; -#ifdef IVAS_FLOAT_FIXED + Word16 ch; + Word16 maxBin; Word32 *tmpBuffer_fx[MAX_OUTPUT_CHANNELS]; Word32 tmpBuffer_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; -#endif + IF( !masaInput->metadataHasBeenFed ) { return IVAS_ERR_MISSING_METADATA; @@ -12608,70 +12608,56 @@ static ivas_error renderInputMasa( masaInput->base.numNewSamplesPerChannel = 0; move32(); -#ifdef IVAS_FLOAT_FIXED - masaInput->base.gain = fix_to_float( masaInput->base.gain_fx, Q30 ); *outAudio.pq_fact = outAudio.q_factor; move16(); /* Apply input gain to new audio */ v_multc_fixed( inAudio.data_fx, masaInput->base.gain_fx, inAudio.data_fx, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); *outAudio.pq_fact = sub( *outAudio.pq_fact, 1 ); // to compensate for the qfactor reduction in gain multiplication. -#endif // IVAS_FLOAT_FIXED - /* Apply input gain to new audio */ - v_multc( inAudio.data, masaInput->base.gain, inAudio.data, inAudio.config.numSamplesPerChannel * inAudio.config.numChannels ); - - maxBin = (Word16) ( *masaInput->base.ctx.pOutSampleRate * INV_CLDFB_BANDWIDTH ); + maxBin = extract_l( Mpy_32_32( *masaInput->base.ctx.pOutSampleRate, INV_CLDFB_BANDWIDTH_Q31 ) ); /* set combined orientation subframe info to start info */ ivas_combined_orientation_set_to_start_index( *( masaInput->base.ctx.pCombinedOrientationData ) ); - if ( EQ_32( getAudioConfigType( outConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_MASA ) ) + IF( EQ_32( getAudioConfigType( outConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_MASA ) ) { /* 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 + ELSE { /* MASA external renderer -> other formats */ - int16_t num_subframes; - for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) - { - tmpBuffer[ch] = tmpBuffer_buff[ch]; - } -#ifdef IVAS_FLOAT_FIXED - for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) + Word16 num_subframes, exp; + FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) { tmpBuffer_fx[ch] = tmpBuffer_buff_fx[ch]; } copyBufferTo2dArray_fx( masaInput->base.inputBuffer, tmpBuffer_buff_fx ); -#endif - copyBufferTo2dArray( masaInput->base.inputBuffer, tmpBuffer_buff ); - num_subframes = (int16_t) ( masaInput->base.inputBuffer.config.numSamplesPerChannel / ( *masaInput->base.ctx.pOutSampleRate / ( IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) ); + num_subframes = BASOP_Util_Divide3232_Scale( L_mult0( masaInput->base.inputBuffer.config.numSamplesPerChannel, IVAS_NUM_FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), *masaInput->base.ctx.pOutSampleRate, &exp ); + num_subframes = shr( num_subframes, sub( 15, exp ) ); - switch ( masaInput->hMasaExtRend->renderer_type ) + 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 ); + intermidiate_ext_dirac_render( masaInput->hMasaExtRend, 1 ); #endif FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state = Q11; } + FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ ) + { + Scale_sig32( tmpBuffer_buff_fx[ch], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + } ivas_masa_ext_dirac_render_fx( masaInput->hMasaExtRend, tmpBuffer_fx, num_subframes ); + + *outAudio.pq_fact = Q11; + move16(); + FOR( ch = 0; ch < masaInput->hMasaExtRend->hDirACRend->hOutSetup.nchan_out_woLFE + masaInput->hMasaExtRend->hDirACRend->hOutSetup.num_lfe; ch++ ) { scale_sig32( masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, masaInput->hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, masaInput->hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); @@ -12679,29 +12665,29 @@ static ivas_error renderInputMasa( } #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 ); + intermidiate_ext_dirac_render( masaInput->hMasaExtRend, 0 ); #endif - break; + 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; + + Scale_sig32( tmpBuffer_buff_fx[0], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + Scale_sig32( tmpBuffer_buff_fx[1], L_FRAME48k, sub( Q11, *outAudio.pq_fact ) ); + + ivas_masa_ext_rend_parambin_render_fx( masaInput->hMasaExtRend, *masaInput->base.ctx.pCombinedOrientationData, tmpBuffer_fx, num_subframes ); + *outAudio.pq_fact = Q11; + move16(); + BREAK; case RENDERER_DISABLE: - break; /* This happens for 1TC MASA to MONO where we just copy input transport to output */ + BREAK; /* This happens for 1TC MASA to MONO where we just copy input transport to output */ default: return ( IVAS_ERROR( IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED, "Wrong output config for MASA input in external renderer\n" ) ); } - accumulate2dArrayToBuffer( tmpBuffer_buff, &outAudio ); + accumulate2dArrayToBuffer_fx( tmpBuffer_buff_fx, &outAudio ); } return IVAS_ERR_OK; @@ -12780,23 +12766,43 @@ static ivas_error renderInputMasa( return IVAS_ERR_OK; } #endif - +#ifdef IVAS_FLOAT_FIXED static ivas_error renderActiveInputsMasa( IVAS_REND_HANDLE hIvasRend, IVAS_REND_AudioBuffer outAudio ) { - int16_t i; + Word16 i; input_masa *pCurrentInput; ivas_error error; -#ifdef IVAS_FLOAT_FIXED - if ( hIvasRend->inputsSba[0].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) + + FOR( ( i = 0, pCurrentInput = hIvasRend->inputsMasa ); i < RENDERER_MAX_MASA_INPUTS; ( ++i, ++pCurrentInput ) ) { - for ( i = 0; i < outAudio.config.numChannels * outAudio.config.numSamplesPerChannel; i++ ) + IF( EQ_16( pCurrentInput->base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) { - outAudio.data[i] = (float) outAudio.data_fx[i] / ( 1 << *outAudio.pq_fact ); + /* Skip inactive inputs */ + CONTINUE; + } + + *outAudio.pq_fact = Q8; + move16(); + + IF( NE_32( ( error = renderInputMasa( pCurrentInput, hIvasRend->outputConfig, outAudio ) ), IVAS_ERR_OK ) ) + { + return error; } } -#endif + + return IVAS_ERR_OK; +} +#else +static ivas_error renderActiveInputsMasa( + IVAS_REND_HANDLE hIvasRend, + IVAS_REND_AudioBuffer outAudio ) +{ + int16_t i; + input_masa *pCurrentInput; + ivas_error error; + for ( i = 0, pCurrentInput = hIvasRend->inputsMasa; i < RENDERER_MAX_MASA_INPUTS; ++i, ++pCurrentInput ) { if ( pCurrentInput->base.inConfig == IVAS_AUDIO_CONFIG_INVALID ) @@ -12805,27 +12811,15 @@ static ivas_error renderActiveInputsMasa( continue; } -#ifdef IVAS_FLOAT_FIXED - *outAudio.pq_fact = Q8; -#endif // IVAS_FLOAT_FIXED if ( ( error = renderInputMasa( pCurrentInput, hIvasRend->outputConfig, outAudio ) ) != IVAS_ERR_OK ) { return error; } -#ifdef IVAS_FLOAT_FIXED - if ( ( hIvasRend->inputsSba[0].base.inConfig != IVAS_AUDIO_CONFIG_INVALID ) && ( getAudioConfigType( hIvasRend->outputConfig ) != IVAS_REND_AUDIO_CONFIG_TYPE_MASA ) ) - { - for ( Word16 k = 0; k < outAudio.config.numChannels * outAudio.config.numSamplesPerChannel; k++ ) - { - outAudio.data_fx[k] = (Word32) outAudio.data[k] * ( 1 << *outAudio.pq_fact ); - } - } -#endif } return IVAS_ERR_OK; } - +#endif /*---------------------------------------------------------------------* * IVAS_REND_GetMasaMetadata( ) @@ -13309,18 +13303,10 @@ static ivas_error getSamplesInternal( test(); test(); - IF( NE_32( hIvasRend->inputsSba[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsMc[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) || NE_32( hIvasRend->inputsIsm[0].base.inConfig, IVAS_AUDIO_CONFIG_INVALID ) ) - { - Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); - limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); - } - ELSE - { - floatToFixed_arrL( outAudio.data, outAudio.data_fx, *outAudio.pq_fact, hIvasRend->hLimiter->num_channels * outAudio.config.numSamplesPerChannel ); - Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); - limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); - fixedToFloat_arrL( outAudio.data_fx, outAudio.data, *outAudio.pq_fact, hIvasRend->hLimiter->num_channels * outAudio.config.numSamplesPerChannel ); - } + + Word32 limiter_thresold = L_lshl( IVAS_LIMITER_THRESHOLD, *outAudio.pq_fact ); + limitRendererOutput_fx( hIvasRend->hLimiter, outAudio.data_fx, outAudio.config.numSamplesPerChannel, limiter_thresold, *outAudio.pq_fact ); + /* update global cominbed orientation start index */ ivas_combined_orientation_update_start_index( hIvasRend->hCombinedOrientationData, outAudio.config.numSamplesPerChannel ); @@ -15143,19 +15129,16 @@ static void freeMasaExtRenderer( #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; + Word16 ch; 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]; + Word16 subframe_idx; + Word16 slot_idx; + Word16 nchan_transport; Word16 tmp; hDirACRend = hMasaExtRend->hDirACRend; @@ -15169,120 +15152,118 @@ static void intermidiate_ext_dirac_render( DirAC_mem = hDirACRend->stack_mem; - if ( to_fix ) + IF( to_fix ) { DirAC_mem.reference_power_smooth_q = DirAC_mem.reference_power_q = Q31; - 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++ ) + move16(); + move16(); + FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) { - IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - else - { - if ( hDirACRend->panningConf == DIRAC_PANNING_HOA3 ) - { - if ( masa_band_mapping == NULL && hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - else if ( ( ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) && ( masa_band_mapping != NULL ) ) || - hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_SHD || hDirACRend->synthesisConf == DIRAC_SYNTHESIS_MONO ) - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - ELSE IF( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) /*VBAP*/ - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - } - else if ( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) /*VBAP*/ - { - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); - hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; - } - } + Scale_sig32( hDirACRend->h_output_synthesis_psd_state.direct_responses_fx, i_mult( hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_dir ), sub( Q30, hDirACRend->h_output_synthesis_psd_state.direct_responses_q ) ); + hDirACRend->h_output_synthesis_psd_state.direct_responses_q = Q30; + move16(); } - if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_len, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth, shift ); } - if ( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_len ); 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, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, shift ); } - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_len, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth, shift ); } + Word16 num_channels_dir = hDirACRend->num_outputs_dir; + move16(); - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; + move16(); } - if ( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) + + IF( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx ) { tmp = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_len, tmp ); - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth += tmp; + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp ); + move16(); } - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_len ); 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, tmp ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev += tmp; + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev, tmp ); + move16(); } scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; + move16(); scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_len, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; - if ( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) + move16(); + IF( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx ) { Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->num_outputs_dir ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_len, shift ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev += shift; + hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev = add( hDirACRend->h_output_synthesis_psd_state.q_cy_auto_dir_smooth_prev, shift ); + move16(); } - if ( hDirACRend->proto_signal_decorr_on == 1 ) + IF( EQ_16( hDirACRend->proto_signal_decorr_on, 1 ) ) { tmp = L_norm_arr( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len ); scale_sig32( hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_fx, hDirACRend->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); - hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer += tmp; + hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( hDirACRend->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp ); + move16(); } - if ( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len > 0 ) + IF( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len > 0 ) { - Word16 shift; + Word16 shift, norm1, norm2; Word32 tmp1, tmp2; maximum_abs_32_fx( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, &tmp2 ); maximum_abs_32_fx( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, &tmp1 ); - shift = s_min( ( tmp1 == 0 ) ? 31 : norm_l( tmp1 ), ( tmp2 == 0 ) ? 31 : norm_l( tmp2 ) ); - Word16 hr_exp = 31 - shift; + IF( tmp1 == 0 ) + { + norm1 = 31; + move16(); + } + ELSE + { + norm1 = norm_l( tmp1 ); + } + + IF( tmp2 == 0 ) + { + norm2 = 31; + move16(); + } + ELSE + { + norm2 = norm_l( tmp2 ); + } + + shift = s_min( norm1, norm2 ); - Scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_fx, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_len, ( 31 - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ) - hr_exp ); - hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = 31 - hr_exp; + Word16 hr_exp = sub( 31, shift ); + + 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( sub( 31, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q ), hr_exp ) ); + hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q = sub( 31, hr_exp ); } FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) @@ -15291,32 +15272,38 @@ static void intermidiate_ext_dirac_render( FOR( ch = 0; ch < nchan_transport; ch++ ) { hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; + move16(); } } - hDirACRend->proto_frame_dec_f_q = 31 - hDirACRend->proto_frame_dec_f_q; + hDirACRend->proto_frame_dec_f_q = sub( 31, hDirACRend->proto_frame_dec_f_q ); + move16(); - if ( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) + IF( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx ) { tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_len, tmp ); - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q += tmp; + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_q, tmp ); + move16(); tmp = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->num_protos_dir * hSpatParamRendCom->num_freq_bands ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_len, tmp ); - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q += tmp; + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( tmp, hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q ); + move16(); } tmp = L_norm_arr( 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, tmp ); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q += tmp; + hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_q, tmp ); + move16(); - if ( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) + IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { tmp = L_norm_arr( 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, tmp ); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q += tmp; + 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, tmp ); + move16(); } } - else + ELSE { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[hSpatParamRendCom->subframes_rendered]; slot_idx++ ) { @@ -15325,17 +15312,15 @@ static void intermidiate_ext_dirac_render( { scale_sig32( hMasaExtRend->cldfbAnaRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbAnaRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbAnaRend[0]->Q_cldfb_state ) ); hMasaExtRend->cldfbAnaRend[ch]->Q_cldfb_state = Q11; + move16(); } } - for ( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) + FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE + hDirACRend->hOutSetup.num_lfe; ch++ ) { scale_sig32( hMasaExtRend->cldfbSynRend[ch]->cldfb_state_fx, hMasaExtRend->cldfbSynRend[ch]->cldfb_size, sub( Q11, hMasaExtRend->cldfbSynRend[0]->Q_cldfb_state ) ); hMasaExtRend->cldfbSynRend[ch]->Q_cldfb_state = Q11; - } - 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 ); + move16(); } } } -- GitLab