From 43020a644a28fad85a78e0e8a9a068c58b344038 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 12:11:55 +0530 Subject: [PATCH 1/2] BASOP addition and instrumentation changes --- lib_com/ivas_cnst.h | 4 + lib_com/ivas_prot.h | 2 +- lib_dec/ivas_binRenderer_internal.c | 324 ++++--- lib_dec/ivas_core_dec.c | 585 ++++++++---- lib_dec/ivas_corecoder_dec_reconfig.c | 95 +- lib_dec/ivas_cpe_dec_fx.c | 467 ++++++---- lib_dec/ivas_dec.c | 4 +- lib_dec/ivas_decision_matrix_dec.c | 33 +- lib_dec/ivas_dirac_dec.c | 1035 +++++++++++++++------ lib_dec/ivas_dirac_output_synthesis_cov.c | 494 ++++++---- 10 files changed, 2087 insertions(+), 956 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 33a48c136..06e5e34b8 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1603,6 +1603,10 @@ typedef enum *----------------------------------------------------------------------------------*/ #define BINAURAL_MAXBANDS 60 /* Max number of bands */ +#ifdef IVAS_FLOAT_FIXED +#define BINAURAL_MAXBANDS_Q25 2013265920 /* Max number of bands in Q25 */ +#define ONE_BY_48000_Q31 44740 +#endif #define BINAURAL_CONVBANDS 50 /* Bands upto which convolution is performed */ #define BINAURAL_NTAPS 3 #define BINAURAL_NTAPS_SBA BINAURAL_NTAPS diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 65770f002..fda8732d9 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -6656,7 +6656,7 @@ void ivas_binRenderer( void ivas_binRenderer_fx( BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ - const int16_t numTimeSlots, /* i : number of time slots to render */ + const Word16 numTimeSlots, /* i : number of time slots to render */ Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ diff --git a/lib_dec/ivas_binRenderer_internal.c b/lib_dec/ivas_binRenderer_internal.c index a00fa71ee..0f92acf2d 100644 --- a/lib_dec/ivas_binRenderer_internal.c +++ b/lib_dec/ivas_binRenderer_internal.c @@ -154,11 +154,21 @@ static void ivas_binRenderer_filterModule_fx( { Word64 outRealLeft_fx = 0, outRealRight_fx = 0, outImagLeft_fx = 0, outImagRight_fx = 0; Word64 W_sub1 = 0, W_add1 = 0, W_sub2 = 0, W_add2 = 0; + move64(); + move64(); + move64(); + move64(); + move64(); + move64(); + move64(); + move64(); FOR( tapIdx = hBinRenderer->hBinRenConvModule->numTapsArray[bandIdx] - 1; tapIdx > 0; tapIdx-- ) { filterStatesLeftRealPtr_fx[tapIdx] = filterStatesLeftRealPtr_fx[tapIdx - 1]; + move32(); filterStatesLeftImagPtr_fx[tapIdx] = filterStatesLeftImagPtr_fx[tapIdx - 1]; + move32(); W_sub1 = W_sub( W_mult0_32_32( filterStatesLeftRealPtr_fx[tapIdx], filterTapsLeftRealPtr_fx[tapIdx] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[tapIdx], filterTapsLeftImagPtr_fx[tapIdx] ) ); // Q29 + Q_filterStates[tapIdx - 1] @@ -169,12 +179,13 @@ static void ivas_binRenderer_filterModule_fx( W_add2 = W_add( W_mult0_32_32( filterStatesLeftRealPtr_fx[tapIdx], filterTapsRightImagPtr_fx[tapIdx] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[tapIdx], filterTapsRightRealPtr_fx[tapIdx] ) ); // Q29 + Q_filterStates[tapIdx - 1] - outRealLeft_fx = W_shr( outRealLeft_fx, Q_filterStates[tapIdx] - Q_filterStates[tapIdx - 1] ); - outImagLeft_fx = W_shr( outImagLeft_fx, Q_filterStates[tapIdx] - Q_filterStates[tapIdx - 1] ); - outRealRight_fx = W_shr( outRealRight_fx, Q_filterStates[tapIdx] - Q_filterStates[tapIdx - 1] ); - outImagRight_fx = W_shr( outImagRight_fx, Q_filterStates[tapIdx] - Q_filterStates[tapIdx - 1] ); + outRealLeft_fx = W_shr( outRealLeft_fx, sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] ) ); + outImagLeft_fx = W_shr( outImagLeft_fx, sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] ) ); + outRealRight_fx = W_shr( outRealRight_fx, sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] ) ); + outImagRight_fx = W_shr( outImagRight_fx, sub( Q_filterStates[tapIdx], Q_filterStates[tapIdx - 1] ) ); Q_filterStates[tapIdx] = Q_filterStates[tapIdx - 1]; + move16(); /* Left Real and Imag */ outRealLeft_fx = W_add( outRealLeft_fx, W_sub1 ); // Q29 + Q_filterStates[1] @@ -186,31 +197,38 @@ static void ivas_binRenderer_filterModule_fx( } filterStatesLeftRealPtr_fx[0] = CLDFB_real[chIdx][k][bandIdx]; + move32(); filterStatesLeftImagPtr_fx[0] = CLDFB_imag[chIdx][k][bandIdx]; + move32(); Q_filterStates[0] = Q_curr; + move16(); /* Left Real and Imag */ // Q29 + Q_curr out_Conv_CLDFB_real[0][k][bandIdx] = W_add( out_Conv_CLDFB_real[0][k][bandIdx], - W_add( W_shr( outRealLeft_fx, Q_filterStates[1] - Q_curr ), + W_add( W_shr( outRealLeft_fx, sub( Q_filterStates[1], Q_curr ) ), W_sub( W_mult0_32_32( filterStatesLeftRealPtr_fx[0], filterTapsLeftRealPtr_fx[0] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[0], filterTapsLeftImagPtr_fx[0] ) ) ) ); // Q29 + move64(); out_Conv_CLDFB_imag[0][k][bandIdx] = W_add( out_Conv_CLDFB_imag[0][k][bandIdx], - W_add( W_shr( outImagLeft_fx, Q_filterStates[1] - Q_curr ), + W_add( W_shr( outImagLeft_fx, sub( Q_filterStates[1], Q_curr ) ), W_add( W_mult0_32_32( filterStatesLeftRealPtr_fx[0], filterTapsLeftImagPtr_fx[0] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[0], filterTapsLeftRealPtr_fx[0] ) ) ) ); // Q29 + move64(); /* Right Real and Imag */ out_Conv_CLDFB_real[1][k][bandIdx] = W_add( out_Conv_CLDFB_real[1][k][bandIdx], - W_add( W_shr( outRealRight_fx, Q_filterStates[1] - Q_curr ), + W_add( W_shr( outRealRight_fx, sub( Q_filterStates[1], Q_curr ) ), W_sub( W_mult0_32_32( filterStatesLeftRealPtr_fx[0], filterTapsRightRealPtr_fx[0] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[0], filterTapsRightImagPtr_fx[0] ) ) ) ); // Q29 + move64(); out_Conv_CLDFB_imag[1][k][bandIdx] = W_add( out_Conv_CLDFB_imag[1][k][bandIdx], - W_add( W_shr( outImagRight_fx, Q_filterStates[1] - Q_curr ), + W_add( W_shr( outImagRight_fx, sub( Q_filterStates[1], Q_curr ) ), W_add( W_mult0_32_32( filterStatesLeftRealPtr_fx[0], filterTapsRightImagPtr_fx[0] ), W_mult0_32_32( filterStatesLeftImagPtr_fx[0], filterTapsRightRealPtr_fx[0] ) ) ) ); // Q29 + move64(); } } } @@ -788,38 +806,46 @@ void ivas_init_binaural_hrtf_fx( HrtfFastConv->leftHRIRImag_HOA3_fx = NULL; HrtfFastConv->rightHRIRReal_HOA3_fx = NULL; HrtfFastConv->rightHRIRImag_HOA3_fx = NULL; - HrtfFastConv->FASTCONV_HOA3_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_HOA3_latency_s_fx = 0; + move32(); HrtfFastConv->leftHRIRReal_fx = NULL; HrtfFastConv->leftHRIRImag_fx = NULL; HrtfFastConv->rightHRIRReal_fx = NULL; HrtfFastConv->rightHRIRImag_fx = NULL; - HrtfFastConv->FASTCONV_HRIR_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_HRIR_latency_s_fx = 0; + move32(); HrtfFastConv->leftBRIRReal_fx = NULL; HrtfFastConv->leftBRIRImag_fx = NULL; HrtfFastConv->rightBRIRReal_fx = NULL; HrtfFastConv->rightBRIRImag_fx = NULL; - HrtfFastConv->FASTCONV_BRIR_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_BRIR_latency_s_fx = 0; + move32(); HrtfFastConv->leftHRIRReal_HOA2_fx = NULL; HrtfFastConv->leftHRIRImag_HOA2_fx = NULL; HrtfFastConv->rightHRIRReal_HOA2_fx = NULL; HrtfFastConv->rightHRIRImag_HOA2_fx = NULL; - HrtfFastConv->FASTCONV_HOA2_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_HOA2_latency_s_fx = 0; + move32(); HrtfFastConv->leftHRIRReal_FOA_fx = NULL; HrtfFastConv->leftHRIRImag_FOA_fx = NULL; HrtfFastConv->rightHRIRReal_FOA_fx = NULL; HrtfFastConv->rightHRIRImag_FOA_fx = NULL; - HrtfFastConv->FASTCONV_FOA_latency_s_fx = 0x00; + HrtfFastConv->FASTCONV_FOA_latency_s_fx = 0; + move32(); - HrtfFastConv->allocate_init_flag = 0x00; + HrtfFastConv->allocate_init_flag = 0; + move16(); FOR( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ ) { - HrtfFastConv->fastconvReverberationTimes_fx[i] = 0x00; - HrtfFastConv->fastconvReverberationEneCorrections_fx[i] = 0x00; + HrtfFastConv->fastconvReverberationTimes_fx[i] = 0; + move32(); + HrtfFastConv->fastconvReverberationEneCorrections_fx[i] = 0; + move32(); } return; @@ -968,135 +994,155 @@ ivas_error ivas_allocate_binaural_hrtf_fx( const Word16 allocate_init_flag /* i : Memory allocation flag */ ) { - IF( input_config == IVAS_AUDIO_CONFIG_HOA3 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_HOA3 ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftHRIRReal_HOA3_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA3_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA3_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA3_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA3" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA3" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA3" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA3_fx, BINAURAL_CONVBANDS, HOA3_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA3" ); } } } - IF( input_config == IVAS_AUDIO_CONFIG_HOA2 || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_HOA2 ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftHRIRReal_HOA2_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_HOA2_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_HOA2_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_HOA2_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_HOA2" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_HOA2" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_HOA2" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_HOA2_fx, BINAURAL_CONVBANDS, HOA2_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_HOA2" ); } } } - IF( input_config == IVAS_AUDIO_CONFIG_FOA || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_FOA ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_FOA ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftHRIRReal_FOA_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_FOA_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_FOA_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_FOA_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal_FOA" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag_FOA" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal_FOA" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_FOA_fx, BINAURAL_CONVBANDS, FOA_CHANNELS, BINAURAL_NTAPS_SBA, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag_FOA" ); } } } - IF( renderer_type == RENDERER_BINAURAL_FASTCONV || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + test(); + IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftHRIRReal_fx != NULL ) && ( HrtfFastConv->leftHRIRImag_fx != NULL ) && ( HrtfFastConv->rightHRIRReal_fx != NULL ) && ( HrtfFastConv->rightHRIRImag_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRReal" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftHRIRImag" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRReal" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightHRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightHRIRImag" ); } } } - IF( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || bin_input_config == BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) + test(); + IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( bin_input_config, BINAURAL_INPUT_AUDIO_CONFIG_COMBINED ) ) { + test(); + test(); + test(); IF( ( HrtfFastConv->leftBRIRReal_fx != NULL ) && ( HrtfFastConv->leftBRIRImag_fx != NULL ) && ( HrtfFastConv->rightBRIRReal_fx != NULL ) && ( HrtfFastConv->rightBRIRImag_fx != NULL ) ) { return IVAS_ERR_OK; } ELSE { - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRReal" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->leftBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for leftBRIRImag" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRReal_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRReal" ); } - IF( IVAS_ERR_OK != ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) + IF( NE_32( IVAS_ERR_OK, ivas_alloc_pppMem_fx( &HrtfFastConv->rightBRIRImag_fx, BINAURAL_CONVBANDS, HRTF_LS_CHANNELS, BINAURAL_NTAPS_MAX, allocate_init_flag ) ) ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for rightBRIRImag" ); } @@ -1269,6 +1315,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( Word16 i, j; ivas_error error; + test(); IF( hHrtfFastConv != NULL && *hHrtfFastConv != NULL ) { /* Tables already loaded from file */ @@ -1286,36 +1333,44 @@ static ivas_error ivas_binaural_hrtf_open_fx( ivas_init_binaural_hrtf_fx( HrtfFastConv ); - IF( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { HrtfFastConv->FASTCONV_HRIR_latency_s_fx = FASTCONV_HRIR_latency_s_fx; + move32(); } - IF( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) ) { HrtfFastConv->FASTCONV_HOA2_latency_s_fx = FASTCONV_HOA2_latency_s_fx; + move32(); } - IF( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { HrtfFastConv->FASTCONV_HOA3_latency_s_fx = FASTCONV_HOA3_latency_s_fx; + move32(); } - IF( input_config == IVAS_AUDIO_CONFIG_FOA ) + if ( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) ) { HrtfFastConv->FASTCONV_FOA_latency_s_fx = FASTCONV_FOA_latency_s_fx; + move32(); } - IF( input_config == IVAS_AUDIO_CONFIG_BINAURAL || renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { HrtfFastConv->FASTCONV_BRIR_latency_s_fx = FASTCONV_BRIR_latency_s_fx; + move32(); } HrtfFastConv->allocate_init_flag = 1; + move16(); - IF( ( error = ivas_allocate_binaural_hrtf_fx( HrtfFastConv, input_config, BINAURAL_INPUT_AUDIO_CONFIG_INVALID, renderer_type, HrtfFastConv->allocate_init_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_allocate_binaural_hrtf_fx( HrtfFastConv, input_config, BINAURAL_INPUT_AUDIO_CONFIG_INVALID, renderer_type, HrtfFastConv->allocate_init_flag ) ), IVAS_ERR_OK ) ) { return error; } FOR( i = 0; i < BINAURAL_CONVBANDS; i++ ) { - IF( renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { FOR( j = 0; j < HRTF_LS_CHANNELS; j++ ) { @@ -1325,7 +1380,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( HrtfFastConv->rightHRIRImag_fx[i][j] = rightHRIRImag_fx[i][j]; } } - ELSE IF( renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + ELSE IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { FOR( j = 0; j < HRTF_LS_CHANNELS; j++ ) { @@ -1335,7 +1390,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( HrtfFastConv->rightBRIRImag_fx[i][j] = rightBRIRImag_fx[i][j]; } } - IF( input_config == IVAS_AUDIO_CONFIG_HOA3 ) + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA3 ) ) { FOR( j = 0; j < HOA3_CHANNELS; j++ ) { @@ -1345,7 +1400,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( HrtfFastConv->rightHRIRImag_HOA3_fx[i][j] = rightHRIRImag_HOA3_fx[i][j]; } } - IF( input_config == IVAS_AUDIO_CONFIG_HOA2 ) + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_HOA2 ) ) { FOR( j = 0; j < HOA2_CHANNELS; j++ ) { @@ -1355,7 +1410,7 @@ static ivas_error ivas_binaural_hrtf_open_fx( HrtfFastConv->rightHRIRImag_HOA2_fx[i][j] = rightHRIRImag_HOA2_fx[i][j]; } } - IF( input_config == IVAS_AUDIO_CONFIG_FOA ) + IF( EQ_32( input_config, IVAS_AUDIO_CONFIG_FOA ) ) { FOR( j = 0; j < FOA_CHANNELS; j++ ) { @@ -1616,24 +1671,22 @@ static void ivas_binaural_obtain_DMX( *-------------------------------------------------------------------------*/ static void ivas_binaural_obtain_DMX_fx( - const int16_t numTimeSlots, + const Word16 numTimeSlots, BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: fastconv binaural renderer handle */ Word32 RealBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals */ Word32 ImagBuffer[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i : Contains the LS signals */ Word32 realDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 imagDMX[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX] ) { - int16_t chIdx, bandIdx, k; + Word16 chIdx, bandIdx, k; - IF( hBinRenderer->ivas_format == MC_FORMAT ) + test(); + IF( EQ_32( hBinRenderer->ivas_format, MC_FORMAT ) ) { /* Obtain the downmix */ - // float P_in[CLDFB_NO_CHANNELS_MAX]; Word32 P_in_fx[CLDFB_NO_CHANNELS_MAX]; - // float P_out, factEQ; Word32 P_out_fx, factEQ_fx; - int16_t chOutIdx; - // float temp1, temp2; + Word16 chOutIdx; Word32 temp1_fx, temp2_fx; FOR( k = 0; k < numTimeSlots; k++ ) @@ -1652,22 +1705,21 @@ static void ivas_binaural_obtain_DMX_fx( FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { Word32 dmxConst = hBinRenderer->hReverb->dmxmtx_fx[chOutIdx][chIdx]; + move32(); FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { FOR( k = 0; k < numTimeSlots; k++ ) { - // temp1 = RealBuffer[chIdx][k][bandIdx] * dmxConst; - // temp2 = ImagBuffer[chIdx][k][bandIdx] * dmxConst; - // realDMX[chOutIdx][k][bandIdx] += temp1; - // imagDMX[chOutIdx][k][bandIdx] += temp2; temp1_fx = Mpy_32_32( RealBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in temp2_fx = Mpy_32_32( ImagBuffer[chIdx][k][bandIdx], dmxConst ); // Q_in realDMX[chOutIdx][k][bandIdx] = L_add( realDMX[chOutIdx][k][bandIdx], temp1_fx ); // Q_in + move32(); imagDMX[chOutIdx][k][bandIdx] = L_add( imagDMX[chOutIdx][k][bandIdx], temp2_fx ); // Q_in + move32(); - // P_in[bandIdx] += temp1 * temp1 + temp2 * temp2; P_in_fx[bandIdx] = L_add( P_in_fx[bandIdx], L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); // Q31-2*Q_in + move32(); } } } @@ -1678,45 +1730,43 @@ static void ivas_binaural_obtain_DMX_fx( FOR( k = 0; k < numTimeSlots; k++ ) { temp1_fx = realDMX[chOutIdx][k][bandIdx]; + move32(); temp2_fx = imagDMX[chOutIdx][k][bandIdx]; - // P_out += temp1 * temp1 + temp2 * temp2; + move32(); P_out_fx = L_add( P_out_fx, L_add( Mpy_32_32( temp1_fx, temp1_fx ), Mpy_32_32( temp2_fx, temp2_fx ) ) ); // Q31-2*Q_in } - // if ( ( factEQ <= 1e-20f ) || ( P_in[bandIdx] <= 1e-20f ) || ( P_out <= 1e-20f ) ) - IF( LE_32( P_in_fx[bandIdx], 0 ) || LE_32( P_out_fx, 0 ) ) + test(); + IF( ( P_in_fx[bandIdx] <= 0 ) || ( P_out_fx <= 0 ) ) { - // factEQ = 1.0f; factEQ_fx = 0x40000000; + move32(); } ELSE { - // factEQ = sqrtf( P_in[bandIdx] / ( P_out + 1e-20f ) ); Word16 div = divide3232( P_in_fx[bandIdx], P_out_fx ); Word16 exp = norm_l( div ); factEQ_fx = Sqrt32( L_shl( div, Q16 ), &exp ); factEQ_fx = L_shl( factEQ_fx, exp - 1 ); // Q30 } - IF( LE_32( factEQ_fx, 0 ) ) + if ( factEQ_fx <= 0 ) { factEQ_fx = 0x40000000; + move32(); } - // factEQ = max( min( factEQ, 2.0f ), 0.5f ); factEQ_fx = L_max( L_min( factEQ_fx, 0x7fffffff ), 0x20000000 ); // Q30 FOR( k = 0; k < numTimeSlots; k++ ) { - // realDMX[chOutIdx][k][bandIdx] *= factEQ; - // imagDMX[chOutIdx][k][bandIdx] *= factEQ; realDMX[chOutIdx][k][bandIdx] = Mpy_32_32( realDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1 + move32(); imagDMX[chOutIdx][k][bandIdx] = Mpy_32_32( imagDMX[chOutIdx][k][bandIdx], factEQ_fx ); // Q_in - 1 + move32(); } } } } - ELSE IF( hBinRenderer->ivas_format == SBA_FORMAT || hBinRenderer->ivas_format == MASA_FORMAT ) + ELSE IF( EQ_32( hBinRenderer->ivas_format, SBA_FORMAT ) || EQ_32( hBinRenderer->ivas_format, MASA_FORMAT ) ) { - // float *outRealLeftPtr, *outImagLeftPtr, *outRealRightPtr, *outImagRightPtr; - // float *inRealPtr, *inImagPtr; Word32 *outRealLeftPtr_fx, *outImagLeftPtr_fx, *outRealRightPtr_fx, *outImagRightPtr_fx; Word32 *inRealPtr_fx, *inImagPtr_fx; @@ -1734,7 +1784,6 @@ static void ivas_binaural_obtain_DMX_fx( FOR( chIdx = 0; chIdx < hBinRenderer->nInChannels; chIdx++ ) { - // float foa_const = hBinRenderer->hReverb->foa_enc[chIdx][1]; Word32 foa_const_fx = L_shl( hBinRenderer->hReverb->foa_enc_fx[chIdx][1], 1 ); // Q30 inRealPtr_fx = (Word32 *) &( RealBuffer[chIdx][k][0] ); @@ -1742,15 +1791,15 @@ static void ivas_binaural_obtain_DMX_fx( FOR( bandIdx = 0; bandIdx < hBinRenderer->conv_band; bandIdx++ ) { - // outRealLeftPtr[bandIdx] += inRealPtr[bandIdx] * ( 1.f + foa_const ); - // outImagLeftPtr[bandIdx] += inImagPtr[bandIdx] * ( 1.f + foa_const ); outRealLeftPtr_fx[bandIdx] = L_add( outRealLeftPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + move32(); outImagLeftPtr_fx[bandIdx] = L_add( outImagLeftPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_add( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + move32(); - // outRealRightPtr[bandIdx] += inRealPtr[bandIdx] * ( 1.f - foa_const ); - // outImagRightPtr[bandIdx] += inImagPtr[bandIdx] * ( 1.f - foa_const ); outRealRightPtr_fx[bandIdx] = L_add( outRealRightPtr_fx[bandIdx], Mpy_32_32( inRealPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + move32(); outImagRightPtr_fx[bandIdx] = L_add( outImagRightPtr_fx[bandIdx], Mpy_32_32( inImagPtr_fx[bandIdx], L_sub( ONE_IN_Q30, foa_const_fx ) ) ); // Q_in - 1 + move32(); } } } @@ -1775,6 +1824,7 @@ ivas_error ivas_binRenderer_open_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * prepare library opening @@ -1789,9 +1839,12 @@ ivas_error ivas_binRenderer_open_fx( /* Define of head rotation has to be done in binRendeder in CLDFB*/ hBinRenderer->rotInCldfb = 0; - IF( st_ivas->ivas_format == MC_FORMAT || st_ivas->ivas_format == SBA_FORMAT ) + move16(); + test(); + if ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_FORMAT ) ) { hBinRenderer->rotInCldfb = 1; + move16(); } @@ -1800,45 +1853,55 @@ ivas_error ivas_binRenderer_open_fx( IF( st_ivas->hIntSetup.is_loudspeaker_setup ) { hBinRenderer->ivas_format = MC_FORMAT; + move32(); } ELSE { hBinRenderer->ivas_format = SBA_FORMAT; + move32(); } - hBinRenderer->max_band = (int16_t) ( ( BINAURAL_MAXBANDS * st_ivas->hDecoderConfig->output_Fs ) / 48000 ); + hBinRenderer->max_band = extract_l( Mpy_32_32( Mpy_32_32( BINAURAL_MAXBANDS_Q25, L_shl( st_ivas->hDecoderConfig->output_Fs, Q6 ) ), ONE_BY_48000_Q31 ) ); convBand = hBinRenderer->max_band; + move16(); hBinRenderer->timeSlots = MAX_PARAM_SPATIAL_SUBFRAMES; /* Corresponds to 5 msec sound to motion latency */ + move16(); - IF( convBand > BINAURAL_CONVBANDS ) + IF( GT_16( convBand, BINAURAL_CONVBANDS ) ) { hBinRenderer->conv_band = BINAURAL_CONVBANDS; + move16(); } ELSE { hBinRenderer->conv_band = convBand; + move16(); } /*LFE rendering switched off by default*/ hBinRenderer->render_lfe = 0; + move16(); - IF( st_ivas->ivas_format != ISM_FORMAT && st_ivas->hIntSetup.is_loudspeaker_setup ) + test(); + if ( NE_32( st_ivas->ivas_format, ISM_FORMAT ) && st_ivas->hIntSetup.is_loudspeaker_setup ) { hBinRenderer->render_lfe = 1; + move16(); } /* Load HRTF tables */ - IF( ( error = ivas_binaural_hrtf_open_fx( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_binaural_hrtf_open_fx( &st_ivas->hHrtfFastConv, st_ivas->hIntSetup.output_config, st_ivas->renderer_type ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM && ( st_ivas->hIntSetup.is_loudspeaker_setup == 0 ) ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hIntSetup.is_loudspeaker_setup == 0 ) ) { IVAS_OUTPUT_SETUP out_setup; /* Allocate memories and buffers needed for convolutional module in CICP19 */ - IF( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, 1, IVAS_AUDIO_CONFIG_7_1_4, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, 1, IVAS_AUDIO_CONFIG_7_1_4, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) ) { return error; } @@ -1847,42 +1910,47 @@ ivas_error ivas_binRenderer_open_fx( IF( st_ivas->hoa_dec_mtx == NULL ) { - IF( ( error = ivas_sba_get_hoa_dec_matrix_fx( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( out_setup, &st_ivas->hoa_dec_mtx, st_ivas->hIntSetup.ambisonics_order ) ), IVAS_ERR_OK ) ) { return error; } } hBinRenderer->hoa_dec_mtx = st_ivas->hoa_dec_mtx; - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx; + move32(); } ELSE { /* Allocate memories and buffers needed for convolutional module */ - IF( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, st_ivas->hIntSetup.is_loudspeaker_setup, st_ivas->hIntSetup.output_config, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_binRenderer_convModuleOpen( hBinRenderer, st_ivas->renderer_type, st_ivas->hIntSetup.is_loudspeaker_setup, st_ivas->hIntSetup.output_config, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) ) { return error; } - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ) { - IF( hBinRenderer->ivas_format == MC_FORMAT ) + IF( EQ_32( hBinRenderer->ivas_format, MC_FORMAT ) ) { - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HRIR_latency_s_fx; + move32(); } ELSE { - IF( hBinRenderer->nInChannels == 16 ) + IF( EQ_16( hBinRenderer->nInChannels, 16 ) ) { - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s_fx; //(int32_t) ( st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s * 1000000000.f ); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA3_latency_s_fx; + move32(); } - ELSE IF( hBinRenderer->nInChannels == 9 ) + ELSE IF( EQ_16( hBinRenderer->nInChannels, 9 ) ) { - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA2_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_HOA2_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_HOA2_latency_s_fx; + move32(); } - ELSE IF( hBinRenderer->nInChannels == 4 ) + ELSE IF( EQ_16( hBinRenderer->nInChannels, 4 ) ) { - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_FOA_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_FOA_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_FOA_latency_s_fx; + move32(); } ELSE { @@ -1893,14 +1961,16 @@ ivas_error ivas_binRenderer_open_fx( ELSE { /* same value for MC or HOA both use MC BRIR*/ - st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx; // (int32_t)(st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s * 1000000000.f); + st_ivas->binaural_latency_ns = st_ivas->hHrtfFastConv->FASTCONV_BRIR_latency_s_fx; + move32(); } } /* Allocate memories needed for reverb module */ - IF( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV && st_ivas->hIntSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_32( st_ivas->hIntSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { - IF( ( error = ivas_binaural_reverb_open_fastconv_fx( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_binaural_reverb_open_fastconv_fx( &( hBinRenderer->hReverb ), hBinRenderer->conv_band, hBinRenderer->timeSlots, &( st_ivas->hRenderConfig->roomAcoustics ), st_ivas->hIntSetup.output_config, st_ivas->hDecoderConfig->output_Fs, st_ivas->hHrtfFastConv ) ), IVAS_ERR_OK ) ) { return error; } @@ -1911,6 +1981,7 @@ ivas_error ivas_binRenderer_open_fx( FOR( k = 0; k < hBinRenderer->nInChannels; k++ ) { hBinRenderer->hReverb->dmxmtx_fx[chIdx][k] = dmxmtx_table_fx[chIdx][k]; + move32(); } } } @@ -1923,17 +1994,19 @@ ivas_error ivas_binRenderer_open_fx( IF( hBinRenderer->hReverb != NULL ) { + test(); + test(); IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 ) { FOR( k = 0; k < 11; k++ ) { - ivas_dirac_dec_get_response_fx( (Word16) L_shr_r( ls_azimuth_CICP19_fx[k], 22 ), (Word16) L_shr_r( ls_elevation_CICP19_fx[k], 22 ), hBinRenderer->hReverb->foa_enc_fx[k], 1, Q29 ); + ivas_dirac_dec_get_response_fx( extract_l( L_shr_r( ls_azimuth_CICP19_fx[k], 22 ) ), extract_l( L_shr_r( ls_elevation_CICP19_fx[k], 22 ) ), hBinRenderer->hReverb->foa_enc_fx[k], 1, Q29 ); // Q29: hBinRenderer->hReverb->foa_enc_fx[k] } } - ELSE IF( st_ivas->ivas_format == MC_FORMAT && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) ) { - IF( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = efap_init_data_fx( &( st_ivas->hEFAPdata ), st_ivas->hIntSetup.ls_azimuth_fx, st_ivas->hIntSetup.ls_elevation_fx, st_ivas->hIntSetup.nchan_out_woLFE, EFAP_MODE_EFAP ) ), IVAS_ERR_OK ) ) { return error; } @@ -2302,6 +2375,7 @@ void ivas_binRenderer_close_fx( BINAURAL_RENDERER_HANDLE *hBinRenderer /* i/o: fastconv binaural renderer handle */ ) { + test(); IF( hBinRenderer == NULL || *hBinRenderer == NULL ) { return; @@ -2426,12 +2500,14 @@ void ivas_binaural_hrtf_close( { Word16 allocate_init_flag; + test(); IF( hHrtfFastConv == NULL || *hHrtfFastConv == NULL ) { return; } allocate_init_flag = ( *hHrtfFastConv )->allocate_init_flag; + move16(); ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRReal_fx, HRTF_LS_CHANNELS, allocate_init_flag ); ivas_free_pppHrtfMem_fx( &( *hHrtfFastConv )->leftHRIRImag_fx, HRTF_LS_CHANNELS, allocate_init_flag ); @@ -2566,22 +2642,35 @@ void ivas_binaural_add_LFE_fx( IF( st_ivas->hBinRenderer != NULL ) { render_lfe = st_ivas->hBinRenderer->render_lfe; + move16(); } ELSE { render_lfe = TRUE; + move16(); } IF( render_lfe ) { - IF( st_ivas->renderer_type == RENDERER_BINAURAL_OBJECTS_TD ) + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) { gain_fx = GAIN_LFE_FX; + move16(); } ELSE { - gain_fx = ( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) ? st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe_fx : GAIN_LFE_FX; + test(); + IF( ( st_ivas->hCrendWrapper != NULL ) && ( st_ivas->hCrendWrapper->hHrtfCrend != NULL ) ) + { + gain_fx = st_ivas->hCrendWrapper->hHrtfCrend->gain_lfe_fx; + move16(); + } + ELSE + { + gain_fx = GAIN_LFE_FX; + move16(); + } } FOR( idx_lfe = 0; idx_lfe < st_ivas->hIntSetup.num_lfe; idx_lfe++ ) { @@ -2590,8 +2679,11 @@ void ivas_binaural_add_LFE_fx( FOR( int idx = 0; idx < output_frame; idx++ ) { input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] = L_shl_sat( input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx], 1 ); // saturating to keep same q + move32(); output_fx[0][idx] = L_add_sat( output_fx[0][idx], input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] ); + move32(); output_fx[1][idx] = L_add_sat( output_fx[1][idx], input_fx[st_ivas->hIntSetup.index_lfe[idx_lfe]][idx] ); + move32(); } } } @@ -2610,7 +2702,7 @@ void ivas_binaural_add_LFE_fx( void ivas_binRenderer_fx( BINAURAL_RENDERER_HANDLE hBinRenderer, /* i/o: binaural renderer handle */ COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i : combined head and external orientation handle*/ - const int16_t numTimeSlots, /* i : number of time slots to render */ + const Word16 numTimeSlots, /* i : number of time slots to render */ Word32 Cldfb_RealBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 Cldfb_ImagBuffer_Binaural_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* o : Binaural signals */ Word32 RealBuffer_fx[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i : LS signals */ @@ -2638,20 +2730,24 @@ void ivas_binRenderer_fx( } /* Head rotation in HOA3 or CICPx */ + test(); + test(); IF( hCombinedOrientationData != NULL && hCombinedOrientationData->enableCombinedOrientation[hCombinedOrientationData->subframe_idx] && hBinRenderer->rotInCldfb ) { IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 ) { /* Rotation in SHD (HOA3) */ - IF( hCombinedOrientationData->shd_rot_max_order == -1 ) + IF( EQ_16( hCombinedOrientationData->shd_rot_max_order, -1 ) ) { rotateFrame_shd_cldfb( RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, 3 ); *Q_in = sub( *Q_in, 1 ); //( Q_in + 14 - 15 ) + move16(); } ELSE IF( hCombinedOrientationData->shd_rot_max_order > 0 ) { rotateFrame_shd_cldfb( RealBuffer_fx, ImagBuffer_fx, hCombinedOrientationData->Rmat_fx[hCombinedOrientationData->subframe_idx], hBinRenderer->hInputSetup->nchan_out_woLFE, numTimeSlots, hCombinedOrientationData->shd_rot_max_order ); *Q_in = sub( *Q_in, 1 ); //( Q_in + 14 - 15 ) + move16(); } } ELSE @@ -2663,7 +2759,8 @@ void ivas_binRenderer_fx( } /* HOA decoding to CICP19 if needed*/ - IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && hBinRenderer->nInChannels != 16 ) + test(); + IF( hBinRenderer->hInputSetup->is_loudspeaker_setup == 0 && NE_16( hBinRenderer->nInChannels, 16 ) ) { ivas_sba2mc_cldfb_fixed( *( hBinRenderer->hInputSetup ), RealBuffer_fx, ImagBuffer_fx, hBinRenderer->nInChannels, hBinRenderer->conv_band, numTimeSlots, hBinRenderer->hoa_dec_mtx ); @@ -2677,7 +2774,9 @@ void ivas_binRenderer_fx( FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ ) { Cldfb_RealBuffer_Binaural_fx[i][j][k] = W_extract_l( W_shr( Cldfb_RealBuffer_Binaural_64fx[i][j][k], 29 ) ); //(*Q_in + 29) - 29 + move32(); Cldfb_ImagBuffer_Binaural_fx[i][j][k] = W_extract_l( W_shr( Cldfb_ImagBuffer_Binaural_64fx[i][j][k], 29 ) ); //(*Q_in + 29) - 29 + move32(); } } } @@ -2708,11 +2807,12 @@ void ivas_binRenderer_fx( { FOR( j = 0; j < numTimeSlots; j++ ) { - FOR( k = 0; k < hBinRenderer->hReverb->numBins; k++ ) { reverbRe_fx[i][j][k] = L_shl( reverbRe_fx[i][j][k], 1 ); //*Q_in + move32(); reverbIm_fx[i][j][k] = L_shl( reverbIm_fx[i][j][k], 1 ); //*Q_in + move32(); } } } diff --git a/lib_dec/ivas_core_dec.c b/lib_dec/ivas_core_dec.c index 0bccf0c82..2f9af21ab 100644 --- a/lib_dec/ivas_core_dec.c +++ b/lib_dec/ivas_core_dec.c @@ -58,45 +58,48 @@ ivas_error ivas_core_dec( SCE_DEC_HANDLE hSCE, /* i/o: SCE decoder structure */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ MCT_DEC_HANDLE hMCT, /* i/o: MCT decoder structure */ - const int16_t n_channels, /* i : number of channels to be decoded */ + const Word16 n_channels, /* i : number of channels to be decoded */ Word32 *output_32_fx[], /* o : output synthesis signal */ Word32 hb_synth_32_fx[][L_FRAME48k], /* o : output HB synthesis signal */ Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX], /* o : DFT buffers */ - const int16_t sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ + const Word16 sba_dirac_stereo_flag /* i : signal stereo output for SBA DirAC */ ) { - int16_t i, n, output_frame; + Word16 i, n, output_frame; Decoder_State **sts, *st; STEREO_ICBWE_DEC_HANDLE hStereoICBWE; STEREO_TD_DEC_DATA_HANDLE hStereoTD; - int16_t sharpFlag[CPE_CHANNELS]; + Word16 sharpFlag[CPE_CHANNELS]; Word16 tmp_buffer_fx[L_FRAME48k]; set_s( tmp_buffer_fx, 0, L_FRAME48k ); - Word16 tmp16 = 0, tmp16_2, j; + Word16 tmp16, tmp16_2, j; + tmp16 = 0; + move16(); Word16 Q_white_exc; Q_white_exc = 0; + move16(); - int16_t tmps, incr; + Word16 tmps, incr; Word32 bwe_exc_extended_fx[CPE_CHANNELS][L_FRAME32k + NL_BUFF_OFFSET]; Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; - int16_t core_switching_flag[CPE_CHANNELS]; + Word16 core_switching_flag[CPE_CHANNELS]; Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]; Word32 old_syn_12k8_16k_fx[CPE_CHANNELS][L_FRAME16k]; - int16_t unbits[CPE_CHANNELS]; - int16_t sid_bw[CPE_CHANNELS]; + Word16 unbits[CPE_CHANNELS]; + Word16 sid_bw[CPE_CHANNELS]; FRAME_MODE frameMode[CPE_CHANNELS]; - int16_t tdm_LRTD_flag; - int32_t element_brate, output_Fs; - int32_t last_element_brate; - int16_t use_cldfb_for_dft; + Word16 tdm_LRTD_flag; + Word32 element_brate, output_Fs; + Word32 last_element_brate; + Word16 use_cldfb_for_dft; Word32 *p_output_mem_fx; - int16_t flag_sec_CNA; - int16_t read_sid_info; - int16_t last_element_mode; - int16_t nchan_out; + Word16 flag_sec_CNA; + Word16 read_sid_info; + Word16 last_element_mode; + Word16 nchan_out; Word32 *save_hb_synth_32_fx; ivas_error error; Word32 L_tmp; @@ -121,6 +124,7 @@ ivas_error ivas_core_dec( #endif error = IVAS_ERR_OK; + move32(); push_wmops( "ivas_core_dec" ); /*------------------------------------------------------------------* @@ -128,24 +132,33 @@ ivas_error ivas_core_dec( *-----------------------------------------------------------------*/ use_cldfb_for_dft = 0; + move16(); tdm_LRTD_flag = -1; + move16(); read_sid_info = 1; /* read SID by default */ + move16(); IF( hSCE != NULL ) { sts = hSCE->hCoreCoder; hStereoICBWE = NULL; element_brate = hSCE->element_brate; + move32(); last_element_brate = hSCE->last_element_brate; /* note: this parameter is unused */ + move32(); last_element_mode = IVAS_SCE; + move16(); hStereoTD = NULL; p_output_mem_fx = NULL; nchan_out = 1; - IF( st_ivas != NULL && st_ivas->ivas_format == ISM_FORMAT ) + move16(); + test(); + IF( st_ivas != NULL && EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ) { - IF( st_ivas->hISMDTX.sce_id_dtx != hSCE->sce_id ) + if ( NE_16( st_ivas->hISMDTX.sce_id_dtx, hSCE->sce_id ) ) { read_sid_info = 0; + move16(); } } } @@ -153,22 +166,37 @@ ivas_error ivas_core_dec( { sts = hCPE->hCoreCoder; element_brate = hCPE->element_brate; + move32(); last_element_brate = hCPE->last_element_brate; + move32(); last_element_mode = hCPE->last_element_mode; + move16(); hStereoICBWE = hCPE->hStereoICBWE; hStereoTD = hCPE->hStereoTD; p_output_mem_fx = hCPE->output_mem_fx[1]; nchan_out = hCPE->nchan_out; + move16(); - IF( hCPE->hStereoTD != NULL ) + if ( hCPE->hStereoTD != NULL ) { tdm_LRTD_flag = hCPE->hCoreCoder[0]->tdm_LRTD_flag; + move16(); } - IF( sts[0]->element_mode == IVAS_CPE_DFT ) + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_DFT ) ) { - use_cldfb_for_dft = ( hCPE->nchan_out == 1 && hCPE->hStereoDft->hConfig->res_cod_mode == STEREO_DFT_RES_COD_OFF ) ? 1 : 0; + test(); + IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) + { + use_cldfb_for_dft = 1; + move16(); + } + ELSE + { + use_cldfb_for_dft = 0; + move16(); + } } } @@ -179,15 +207,18 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); st->cldfbAna->Q_cldfb_state = Q10; + move16(); } IF( st->cldfbSynHB ) { scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q10, Q11 ) ); st->cldfbSynHB->Q_cldfb_state = Q10; + move16(); } } output_Fs = sts[0]->output_Fs; + move32(); output_frame = extract_l( Mpy_32_16_1( output_Fs, INV_FRAME_PER_SEC_Q15 ) ); FOR( n = 0; n < n_channels; n++ ) @@ -199,37 +230,56 @@ ivas_error ivas_core_dec( *-----------------------------------------------------------------*/ frameMode[n] = FRAMEMODE_NORMAL; + move32(); st->rate_switching_reset = 0; - + move16(); st->mdct_sw = MODE1; - + move16(); sid_bw[n] = -1; + move16(); core_switching_flag[n] = 0; + move16(); sharpFlag[n] = 0; + move16(); unbits[n] = 0; + move16(); st->GSC_IVAS_mode = 0; + move16(); st->element_brate = element_brate; - + move32(); st->use_partial_copy = 0; + move16(); st->rf_flag = 0; + move16(); st->rf_frame_type = RF_NO_DATA; + move16(); - IF( st->bfi == 1 ) + IF( EQ_16( st->bfi, 1 ) ) { frameMode[n] = FRAMEMODE_MISSING; + move32(); st->coder_type = st->last_coder_type; + move16(); } ELSE { - IF( !( st->element_mode == IVAS_CPE_TD && n == 1 ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ + test(); + IF( !( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) ) ) /* coder_type for SCh in TD stereo is already read in tdm_configure_dec() */ { st->coder_type = INACTIVE; + move16(); } st->extl = -1; + move16(); st->flagGuidedAcelp = 0; + move16(); } - IF( !st->bfi && st->prev_bfi && ( st->last_core_bfi == TCX_20_CORE || st->last_core_bfi == TCX_10_CORE ) && st->hTcxDec != NULL ) + test(); + test(); + test(); + test(); + IF( !st->bfi && st->prev_bfi && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && st->hTcxDec != NULL ) { conceal_eof_gain32 = L_shl( L_deposit_l( st->hTcxDec->conceal_eof_gain ), 1 ); @@ -257,40 +307,47 @@ ivas_error ivas_core_dec( * Decision matrix (selection of technologies) *-----------------------------------------------------------------*/ - IF( st->bfi != 1 ) + test(); + test(); + IF( NE_16( st->bfi, 1 ) ) { ivas_decision_matrix_dec_fx( st, &sharpFlag[n], &core_switching_flag[n], element_brate, nchan_out ); synchonize_channels_mdct_sid_fx( sts, n ); - IF( st->bfi != 1 ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ + IF( NE_16( st->bfi, 1 ) ) /* note: st->bfi can be changed from 0 to 1 in ivas_decision_matrix_dec() when BER is detected */ { - st->sr_core = st->L_frame * FRAMES_PER_SEC; + st->sr_core = L_mult0( st->L_frame, FRAMES_PER_SEC ); st->fscale_old = st->fscale; + move16(); st->fscale = sr2fscale( st->sr_core ); } ELSE { frameMode[n] = FRAMEMODE_MISSING; + move32(); } } - ELSE IF( st->element_mode >= IVAS_SCE && st->prev_bfi == 1 && st->last_con_tcx == 1 ) + ELSE IF( GE_16( st->element_mode, IVAS_SCE ) && EQ_16( st->prev_bfi, 1 ) && EQ_16( st->last_con_tcx, 1 ) ) { st->core = TCX_20_CORE; + move16(); } } /* n_channels loop */ /* MDCT stereo -> DFT stereo switching */ - IF( hCPE != NULL && hCPE->last_element_mode == IVAS_CPE_MDCT && hCPE->element_mode == IVAS_CPE_DFT ) + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { Word16 ovl, fade_len; - IF( sts[0]->L_frame != sts[0]->last_L_frame ) + IF( NE_16( sts[0]->L_frame, sts[0]->last_L_frame ) ) { - Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - sts[0]->hHQ_core->Q_old_wtda_LB ); + Copy_Scale_sig_16_32( sts[0]->hHQ_core->old_out_LB_fx, sts[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, sts[0]->hHQ_core->Q_old_wtda_LB ) ); L_lerp_fx_q11( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_outLB_fx, sts[0]->L_frame, sts[0]->last_L_frame ); - Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sts[0]->hHQ_core->Q_old_wtda_LB - Q11 ); + Copy_Scale_sig_32_16( sts[0]->hHQ_core->old_outLB_fx, sts[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( sts[0]->hHQ_core->Q_old_wtda_LB, Q11 ) ); } - IF( sts[0]->L_frame != L_FRAME16k ) + IF( NE_16( sts[0]->L_frame, L_FRAME16k ) ) { ovl = mult( sts[0]->L_frame, 5120 ); /*STEREO_DFT32MS_OVL_16k/L_FRAME16k = 5/32 = 5120 (Q15)*/ L_lerp_fx_q11( hCPE->input_mem_LB_fx[0], hCPE->input_mem_LB_fx[0], ovl, STEREO_DFT32MS_OVL_16k ); @@ -300,12 +357,17 @@ ivas_error ivas_core_dec( } } + test(); IF( hCPE != NULL && hCPE->hStereoCng != NULL ) { hCPE->hStereoCng->flag_cna_fade = 0; + move16(); } - IF( sba_dirac_stereo_flag && hSCE && sts[0]->total_brate <= SID_2k40 && sts[0]->cng_type == FD_CNG ) + test(); + test(); + test(); + IF( sba_dirac_stereo_flag && hSCE && LE_32( sts[0]->total_brate, SID_2k40 ) && EQ_16( sts[0]->cng_type, FD_CNG ) ) { save_hb_synth_32_fx = hSCE->save_hb_synth_fx; } @@ -318,7 +380,8 @@ ivas_error ivas_core_dec( * Decode SID for MDCT-Stereo DTX mode *-----------------------------------------------------------------*/ - IF( sts[0]->element_mode == IVAS_CPE_MDCT && sts[0]->total_brate == SID_2k40 ) + test(); + IF( EQ_16( sts[0]->element_mode, IVAS_CPE_MDCT ) && EQ_32( sts[0]->total_brate, SID_2k40 ) ) { IF( sts[0]->cng_sba_flag ) { @@ -334,7 +397,9 @@ ivas_error ivas_core_dec( * Sanity check in combined format coding *-----------------------------------------------------------------*/ - IF( hCPE != NULL && hCPE->element_mode == IVAS_CPE_DFT && hCPE->brate_surplus > 0 ) + test(); + test(); + IF( hCPE != NULL && EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && hCPE->brate_surplus > 0 ) { ivas_combined_format_brate_sanity( hCPE->element_brate, sts[0]->core, sts[0]->total_brate, &( sts[0]->core_brate ), &( sts[0]->inactive_coder_type_flag ), &tmps ); } @@ -351,28 +416,32 @@ ivas_error ivas_core_dec( * Initialization *-----------------------------------------------------------------*/ - IF( st->bfi == 1 ) + IF( EQ_16( st->bfi, 1 ) ) { - st->nbLostCmpt++; + st->nbLostCmpt = add( st->nbLostCmpt, 1 ); } ELSE { - IF( st->prev_bfi == 1 ) + IF( EQ_16( st->prev_bfi, 1 ) ) { st->prev_nbLostCmpt = st->nbLostCmpt; + move16(); } ELSE { st->prev_nbLostCmpt = 0; + move16(); } st->nbLostCmpt = 0; + move16(); } st->enablePlcWaveadjust = 0; + move16(); - IF( n == 1 ) + IF( EQ_16( n, 1 ) ) { - sts[1]->BER_detect |= sts[0]->BER_detect; + sts[1]->BER_detect = s_or( sts[1]->BER_detect, sts[0]->BER_detect ); } /*---------------------------------------------------------------------* @@ -384,19 +453,26 @@ ivas_error ivas_core_dec( /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ - Word16 Q_olapBufferSynth = 15, Q_olapBufferSynth2 = 15; /*Initializing with max values to avoid warnings*/ + Word16 Q_olapBufferSynth, Q_olapBufferSynth2; + + Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ + Q_olapBufferSynth2 = Q15; /*Initializing with max values to avoid warnings*/ + move16(); + move16(); Copy_Scale_sig_16_32( st->previoussynth_fx, st->previoussynth_fx_32, L_FRAME48k, 0 ); - IF( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = core_switching_pre_dec_ivas_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) { return error; } flag_sec_CNA = -1; + move16(); IF( hCPE != NULL ) { flag_sec_CNA = sts[1]->flag_cna; + move16(); } /*---------------------------------------------------------------------* @@ -405,7 +481,7 @@ ivas_error ivas_core_dec( * HQ core decoding *---------------------------------------------------------------------*/ - IF( st->core == ACELP_CORE ) + IF( EQ_16( st->core, ACELP_CORE ) ) { /* ACELP core decoder */ Word16 old_syn_12k8_16k_fx_16[L_FRAME16k]; @@ -420,127 +496,184 @@ ivas_error ivas_core_dec( save_hb_synth_16_fx = NULL; } - /* float2fix, to be removed */ IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; + move16(); } IF( st->cldfbBPF ) { scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q10, Q11 ) ); st->cldfbBPF->Q_cldfb_state = Q10; + move16(); } IF( st->cldfbSyn ) { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q10, Q11 ) ); st->cldfbSyn->Q_cldfb_state = Q10; + move16(); } IF( st->hFdCngDec != NULL ) { Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); st->hFdCngDec->msNoiseEst_exp = 27; + move16(); - Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, norm_s( st->hFdCngDec->hFdCngCom->A_cng[0] - 1 ) - 3 ); + Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, add( M, 1 ), sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 3 ) ); } - IF( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE == NULL ? NULL : hCPE->hStereoCng, read_sid_info ) ) != IVAS_ERR_OK ) + IF( hCPE == NULL ) { - return error; + IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, NULL, read_sid_info ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + ELSE + { + IF( NE_32( ( error = acelp_core_dec_ivas_fx( st, output_16_fx[n], synth_16_fx[n], save_hb_synth_16_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx_16, sharpFlag[n], pitch_buf_fx[n], &unbits[n], &sid_bw[n], hStereoTD, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, use_cldfb_for_dft, last_element_mode, last_element_brate, flag_sec_CNA, nchan_out, hCPE->hStereoCng, read_sid_info ) ), IVAS_ERR_OK ) ) + { + return error; + } } - /* fix2float, to be removed */ - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - st->Q_syn2 ); - Scale_sig( output_16_fx[n], L_FRAME48k, -st->Q_syn2 ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, st->Q_syn2 ) ); + Scale_sig( output_16_fx[n], L_FRAME48k, negate( st->Q_syn2 ) ); IF( st->cldfbAna ) { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q10, Q11 ) ); /* 9 * (Word16)(st->L_frame * FRAMES_PER_SEC * INV_CLDFB_BANDWIDTH + 0.5f) */ st->cldfbAna->Q_cldfb_state = Q10; + move16(); } IF( st->cldfbBPF ) { scale_sig32( st->cldfbBPF->cldfb_state_fx, st->cldfbBPF->cldfb_size, sub( Q11, Q10 ) ); st->cldfbBPF->Q_cldfb_state = Q11; + move16(); } IF( st->cldfbSyn ) { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSyn->Q_cldfb_state = Q11; + move16(); } st->prev_Q_syn = st->Q_syn; + move16(); if ( save_hb_synth_32_fx ) { Copy_Scale_sig_16_32( save_hb_synth_16_fx, save_hb_synth_32_fx, output_frame, Q11 ); hSCE->q_save_hb_synth_fx = Q11; + move16(); } - Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, Q11 - ( -1 ) ); + Copy_Scale_sig_16_32( old_syn_12k8_16k_fx_16, old_syn_12k8_16k_fx[n], L_FRAME16k, sub( Q11, negate( Q1 ) ) ); } Copy_Scale_sig_32_16( st->previoussynth_fx_32, st->previoussynth_fx, L_FRAME48k, 0 ); + test(); + test(); + test(); IF( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) ) && NE_16( st->element_mode, IVAS_CPE_MDCT ) ) { - Word16 Qsyn_temp = st->Q_syn; + Word16 Qsyn_temp; + STEREO_CNG_DEC_HANDLE hStereoCng; + IVAS_FORMAT ivas_format; + + Qsyn_temp = st->Q_syn; + move16(); st->Q_syn = 0; + move16(); st->prev_Q_syn = st->Q_syn; + move16(); st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; - + move16(); st->mem_error = st->hBPF->pst_mem_deemp_err_fx; + move32(); /* TCX decoder */ Scale_sig( st->hPFstat->mem_stp, L_SUBFR, -Qsyn_temp ); Scale_sig( st->hPFstat->mem_pf_in, L_SUBFR, -Qsyn_temp ); Scale_sig32( st->hFdCngDec->msNoiseEst, NPART_SHAPING, sub( st->hFdCngDec->msNoiseEst_exp, 27 ) ); st->hFdCngDec->msNoiseEst_exp = 27; + move16(); Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, -st->hHQ_core->Q_old_wtda_LB ); Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); - stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hCPE == NULL ? NULL : hCPE->hStereoCng, nchan_out, st_ivas == NULL ? 0 : st_ivas->ivas_format ); + IF( hCPE == NULL ) + { + hStereoCng = NULL; + } + ELSE + { + hStereoCng = hCPE->hStereoCng; + } + IF( st_ivas == NULL ) + { + ivas_format = 0; + move32(); + } + ELSE + { + ivas_format = st_ivas->ivas_format; + move32(); + } + stereo_tcx_core_dec_fx( st, frameMode[n], output_16_fx[n], synth_16_fx[n], pitch_buf_fx[n], sba_dirac_stereo_flag, hStereoTD, last_element_mode, flag_sec_CNA, hStereoCng, nchan_out, ivas_format ); st->hHQ_core->Q_old_wtda_LB = st->hHQ_core->Q_old_wtda; + move16(); Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 ); IF( st->hTcxDec ) { st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); st->hTcxDec->conLastFrameLevel = st->hTcxDec->LastFrameLevel_bfi_fx; + move16(); } - st->hBPF->pst_mem_deemp_err_fx = (Word16) st->mem_error; + st->hBPF->pst_mem_deemp_err_fx = extract_l( st->mem_error ); } IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ + Word16 Q_output; + + Q_output = 0; + move16(); Q_synth = 0; - Word16 Q_output = 0; + move16(); ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_16_fx[n], &Q_output ); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - Q_output ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_output ) ); #ifdef MSAN_FIX - Scale_sig( synth_16_fx[n], output_frame, -Q_synth ); + Scale_sig( synth_16_fx[n], output_frame, negate( Q_synth ) ); #else - Scale_sig( synth_16_fx[n], L_FRAME48k, -Q_synth ); + Scale_sig( synth_16_fx[n], L_FRAME48k, negate( Q_synth ) ); #endif - Scale_sig( output_16_fx[n], L_FRAME48k, -Q_output ); + Scale_sig( output_16_fx[n], L_FRAME48k, negate( Q_output ) ); } /*---------------------------------------------------------------------* * TD stereo updates *---------------------------------------------------------------------*/ - IF( st->element_mode == IVAS_CPE_TD && n == 0 ) + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && n == 0 ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10 ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); td_stereo_param_updt_fx( st->lsp_old_fx, st->lsf_old_fx, st->old_pitch_buf_16_fx + st->nb_subfr, tdm_lspQ_PCh_fx, tdm_lsfQ_PCh_fx, hStereoTD->tdm_Pri_pitch_buf_fx, st->flag_ACELP16k, hStereoTD->tdm_use_IAWB_Ave_lpc, Q6 ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10 ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), Q10 ); } } /* n_channels loop */ @@ -564,11 +697,13 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; + move16(); } IF( st->cldfbSynHB ) { scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSynHB->Q_cldfb_state = Q11; + move16(); } } @@ -577,31 +712,43 @@ ivas_error ivas_core_dec( } ELSE { - Word16 e_sig = 17; + Word16 e_sig; Word16 ch; + + e_sig = 17; + move16(); sts = hCPE->hCoreCoder; FOR( ch = 0; ch < CPE_CHANNELS; ch++ ) { st = sts[ch]; st->last_gain_syn_deemph = 0; + move16(); IF( st->hHQ_core ) { st->hHQ_core->Q_fer_samples = 0; + move16(); } #ifdef FIX_778_STEREO_BRATE_SWITCHING st->Q_syn = 0; move16(); #endif st->prev_Q_syn = st->Q_syn; + move16(); - Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, st->Q_syn - st->hHQ_core->Q_old_wtda_LB ); - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, st->Q_syn - st->hHQ_core->Q_old_wtda ); + Scale_sig( st->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda_LB ) ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, sub( st->Q_syn, st->hHQ_core->Q_old_wtda ) ); IF( st->hTcxDec ) - st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + { + st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi; + move16(); + } IF( st->hTcxDec ) - st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + { + st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi; + move16(); + } } stereo_mdct_core_dec_fx( st_ivas, hCPE, output_32_fx, synth_16_fx ); @@ -610,39 +757,41 @@ ivas_error ivas_core_dec( { st = hCPE->hCoreCoder[ch]; st->hHQ_core->Q_old_wtda_LB = st->Q_syn; + move16(); st->hHQ_core->Q_old_wtda = st->Q_syn; + move16(); } #ifdef MSAN_FIX - Scale_sig( synth_16_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, e_sig - 15 ); - Scale_sig( synth_16_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, e_sig - 15 ); + Scale_sig( synth_16_fx[0], hCPE->hCoreCoder[0]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); + Scale_sig( synth_16_fx[1], hCPE->hCoreCoder[1]->hTcxDec->L_frameTCX, sub( e_sig, 15 ) ); #else - Scale_sig( synth_16_fx[0], L_FRAME48k, e_sig - 15 ); - Scale_sig( synth_16_fx[1], L_FRAME48k, e_sig - 15 ); + Scale_sig( synth_16_fx[0], L_FRAME48k, sub( e_sig, 15 ) ); + Scale_sig( synth_16_fx[1], L_FRAME48k, sub( e_sig, 15 ) ); #endif } } /* for inactive frames with mono output, copy and (if necessary) downmix buffers */ - ELSE IF( hCPE->nchan_out == 1 ) + ELSE IF( EQ_16( hCPE->nchan_out, 1 ) ) { sts[0] = hCPE->hCoreCoder[0]; sts[1] = hCPE->hCoreCoder[1]; - IF( hCPE->last_element_brate <= IVAS_SID_5k2 ) + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { - sts[0]->hHQ_core->exp_old_out = 15 - sts[0]->hHQ_core->Q_old_wtda; - sts[1]->hHQ_core->exp_old_out = 15 - sts[1]->hHQ_core->Q_old_wtda; + sts[0]->hHQ_core->exp_old_out = sub( 15, sts[0]->hHQ_core->Q_old_wtda ); + sts[1]->hHQ_core->exp_old_out = sub( 15, sts[1]->hHQ_core->Q_old_wtda ); } updateBuffersForDmxMdctStereo_fx( hCPE, output_frame, output_32_fx[0], output_32_fx[1], synth_16_fx ); - IF( hCPE->last_element_brate <= IVAS_SID_5k2 ) + IF( LE_32( hCPE->last_element_brate, IVAS_SID_5k2 ) ) { - sts[0]->hHQ_core->Q_old_wtda = 15 - sts[0]->hHQ_core->exp_old_out; - sts[1]->hHQ_core->Q_old_wtda = 15 - sts[1]->hHQ_core->exp_old_out; + sts[0]->hHQ_core->Q_old_wtda = sub( 15, sts[0]->hHQ_core->exp_old_out ); + sts[1]->hHQ_core->Q_old_wtda = sub( 15, sts[1]->hHQ_core->exp_old_out ); } } test(); - IF( EQ_16( sts[0]->bfi, 0 ) && EQ_16( sts[0]->prev_bfi, 1 ) ) + IF( sts[0]->bfi == 0 && EQ_16( sts[0]->prev_bfi, 1 ) ) { /* On first good frame after frameloss undo the whitening of the bg noise shape */ FOR( n = 0; n < n_channels; ++n ) @@ -651,6 +800,7 @@ ivas_error ivas_core_dec( { Scale_sig32( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, sub( sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 27 ) ); sts[n]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = 27; + move16(); TonalMdctConceal_whiten_noise_shape_ivas_fx( sts[n], L_FRAME16k, ON_FIRST_GOOD_FRAME ); } @@ -662,13 +812,20 @@ ivas_error ivas_core_dec( * Stereo CNG updates *---------------------------------------------------------------------*/ + test(); IF( EQ_16( sts[0]->element_mode, IVAS_CPE_TD ) && hCPE->hStereoCng != NULL ) { /* To be cleaned up once the caller function is converted // These changes are for system testing of fixed changes made */ - Word16 Q_c_PS_LT = 31, Q_output = 11; + Word16 Q_c_PS_LT, Q_output; + Word32 c_PS_LT_fx; - Word32 c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); + Q_c_PS_LT = 31; + move16(); + Q_output = 11; + move16(); + c_PS_LT_fx = L_deposit_h( hCPE->hStereoCng->c_PS_LT_fx ); Q_c_PS_LT = Q31; + move16(); stereo_cng_compute_PScorr_fx( output_32_fx[0], output_32_fx[1], &Q_output, &c_PS_LT_fx, Q_c_PS_LT, sts[0]->L_frame, sts[1]->L_frame ); @@ -689,10 +846,11 @@ ivas_error ivas_core_dec( /*core_switching_post_dec*/ Q_synth = 0; + move16(); if ( st->hHQ_core != NULL ) { st->hHQ_core->Q_old_postdec = 0; - // st->hHQ_core->Q_old_wtda = 0; + move16(); } /*------------------fix-to-fix-end-----------------------*/ @@ -711,12 +869,13 @@ ivas_error ivas_core_dec( set16_fx( output_mem_16_fx, 0, NS2SA( st->output_Fs, 3125000 ) ); } - Scale_sig32( output_32_fx[n], L_FRAME48k, Q4 - Q11 ); + Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q4, Q11 ) ); IF( st->hHQ_core != NULL ) { - Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, -st->hHQ_core->Q_old_wtda ); + Scale_sig( st->hHQ_core->old_out_fx, L_FRAME48k, negate( st->hHQ_core->Q_old_wtda ) ); st->hHQ_core->Q_old_wtda = 0; + move16(); } /*size of synth is choosen as delay comp to start with*/ @@ -726,11 +885,14 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q4, Q11 ) ); st->cldfbSyn->Q_cldfb_state = Q4; + move16(); } Word16 q_audio, old_syn_fx; old_syn_fx = Q11; + move16(); q_audio = Q12; + move16(); test(); test(); test(); @@ -748,27 +910,25 @@ ivas_error ivas_core_dec( ELSE IF( EQ_16( st->bwidth, WB ) && EQ_16( st->last_extl, WB_TBE ) ) { GenTransition_WB_fixed( st->hBWE_TD, hb_synth_32_fx[n], output_Fs ); - - move16(); } /* Memories Scaling */ - Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, st->prev_Q_bwe_syn2 - Q11 ); - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11 ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), st->prev_Qx - Q11 ); - Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), st->prev_Qx - Q11 ); - Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, st->prev_Qx - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_TD->syn_overlap_fx_32, st->hBWE_TD->syn_overlap_fx, L_SHB_LAHEAD, sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->state_lsyn_filt_shb_fx_32, st->hBWE_TD->state_lsyn_filt_shb_fx, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( st->prev_Qx, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->mem_resamp_HB_fx_32, st->hBWE_TD->mem_resamp_HB_fx, INTERP_3_1_MEM_LEN, sub( st->prev_Qx, Q11 ) ); } /* Memories Re-Scaling */ IF( st->hBWE_TD != NULL ) { - Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, Q11 - st->prev_Q_bwe_syn2 ); - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, Q11 - st->prev_Qx ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), Q11 - st->prev_Qx ); - Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), Q11 - st->prev_Qx ); - Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, Q11 - st->prev_Qx ); - Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, 2 * ALLPASSSECTIONS_STEEP ); + Copy_Scale_sig_16_32( st->hBWE_TD->syn_overlap_fx, st->hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, st->prev_Q_bwe_syn2 ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_dwn_shb_fx, st->hBWE_TD->state_lsyn_filt_dwn_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->state_lsyn_filt_shb_fx, st->hBWE_TD->state_lsyn_filt_shb_fx_32, shl( ALLPASSSECTIONS_STEEP, 1 ), sub( Q11, st->prev_Qx ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->mem_resamp_HB_fx_32, INTERP_3_1_MEM_LEN, sub( Q11, st->prev_Qx ) ); + Copy( st->hBWE_TD->mem_resamp_HB_fx, st->hBWE_TD->state_32and48k_WB_upsample_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ) ); } /*---------------------------------------------------------------------* * Postprocessing for ACELP/MDCT core switching @@ -780,10 +940,31 @@ ivas_error ivas_core_dec( test(); IF( sba_dirac_stereo_flag && NE_16( st->element_mode, IVAS_CPE_MDCT ) && !( EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) ) { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, hSCE->q_save_synth_fx - Q_synth ); + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); } - IF( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ( st_ivas != NULL ) ? st_ivas->ivas_format : UNDEFINED_FORMAT, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, ( hCPE != NULL ) ? hCPE->last_element_mode : IVAS_SCE, &Q_synth ) ) != IVAS_ERR_OK ) + IVAS_FORMAT ivas_format; + IF( st_ivas != NULL ) + { + ivas_format = st_ivas->ivas_format; + move32(); + } + ELSE + { + ivas_format = UNDEFINED_FORMAT; + move32(); + } + IF( hCPE != NULL ) + { + last_element_mode = hCPE->last_element_mode; + move16(); + } + ELSE + { + last_element_mode = IVAS_SCE; + move16(); + } + IF( NE_32( ( error = core_switching_post_dec_ivas_fx( st, synth_16_fx[n], output_32_fx[n], p_output_mem_16, ivas_format, use_cldfb_for_dft, output_frame, 0 /*core_switching_flag*/, sba_dirac_stereo_flag, nchan_out, last_element_mode, &Q_synth ) ), IVAS_ERR_OK ) ) { return error; } @@ -794,7 +975,7 @@ ivas_error ivas_core_dec( test(); IF( sba_dirac_stereo_flag && hSCE && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) { - Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, hSCE->q_save_synth_fx - Q_synth ); + Copy_Scale_sig_16_32( synth_16_fx[n], hSCE->save_synth_fx, output_frame, sub( hSCE->q_save_synth_fx, Q_synth ) ); } /* if we transition from inactive to active coding in MDCT-Stereo DTX and the output format is mono DMX, we need to sync the upsampled buffer between channels here */ @@ -803,7 +984,7 @@ ivas_error ivas_core_dec( test(); test(); test(); - IF( EQ_16( n, 0 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) + IF( n == 0 && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->last_core, ACELP_CORE ) && NE_16( st->core, ACELP_CORE ) && ( EQ_16( nchan_out, 1 ) || ( hCPE != NULL && EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) ) ) { Copy( sts[0]->previoussynth_fx, sts[1]->previoussynth_fx, st->hTcxDec->L_frameTCX ); } @@ -813,8 +994,8 @@ ivas_error ivas_core_dec( ivas_bw_switching_pre_proc_fx( st, last_element_brate, nchan_out, old_syn_12k8_16k_fx[n], old_syn_fx, q_audio ); - Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, HQ_DELTA_MAX * HQ_DELAY_COMP, Q11 ); - Scale_sig32( output_32_fx[n], L_FRAME48k, Q11 - Q4 ); + Copy_Scale_sig_16_32( st->delay_buf_out_fx, st->delay_buf_out32_fx, imult1616( HQ_DELTA_MAX, HQ_DELAY_COMP ), Q11 ); + Scale_sig32( output_32_fx[n], L_FRAME48k, sub( Q11, Q4 ) ); /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/ @@ -823,6 +1004,7 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbSyn->cldfb_state_fx, st->cldfbSyn->p_filter_length, sub( Q11, Q4 ) ); st->cldfbSyn->Q_cldfb_state = Q11; + move16(); } #ifdef MSAN_FIX @@ -833,15 +1015,20 @@ ivas_error ivas_core_dec( /*------------------reset-code-start---------------------*/ + test(); + test(); IF( NE_16( st->last_extl, WB_BWE ) && EQ_16( st->extl, WB_BWE ) && st->hBWE_FD != NULL ) { - + test(); IF( NE_16( st->last_extl, SWB_BWE ) && NE_16( st->last_extl, FB_BWE ) ) { st->hBWE_FD->prev_mode = st->hBWE_FD->prev_mode; + move16(); } st->hBWE_FD->prev_L_swb_norm = st->hBWE_FD->prev_L_swb_norm; + move16(); st->hBWE_FD->prev_flag = st->hBWE_FD->prev_flag; + move16(); } /*---------------------------------------------------------------------* @@ -853,7 +1040,9 @@ ivas_error ivas_core_dec( Word16 Q_syn_hb; Q_input = 0; + move16(); Q_hb_synth_fx = 0; + move16(); Q_synth_fx = 0; move16(); @@ -874,28 +1063,28 @@ ivas_error ivas_core_dec( ivas_wb_tbe_dec_fx( st, st->coder_type, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], hb_synth_16_fx[n], &Q_hb_synth_fx ); } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && EQ_16( st->bws_cnt, 0 ) && EQ_32( st->extl_brate, 0 ) ) + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( n, 1 ) && !tdm_LRTD_flag && NE_16( st->extl, -1 ) && st->bws_cnt == 0 && st->extl_brate == 0 ) { /* do nothing */ } - ELSE IF( EQ_16( st->extl, WB_BWE ) && EQ_16( st->bws_cnt, 0 ) ) + ELSE IF( EQ_16( st->extl, WB_BWE ) && st->bws_cnt == 0 ) { /* WB BWE decoder */ Q_hb_synth_fx = ivas_wb_bwe_dec_fx( st, output_16_fx[n], synth_16_fx[n], hb_synth_16_fx[n], use_cldfb_for_dft, output_frame, voice_factors_fx[n], pitch_buf_fx[n], &Q_synth_fx ); } /* Memories Re-Scaling */ - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, Q11 - Q_hb_synth_fx ); - Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, Q11 - Q_input ); - Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, Q11 - Q_synth_fx ); + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, sub( Q11, Q_hb_synth_fx ) ); + Copy_Scale_sig_16_32( output_16_fx[n], output_32_fx[n], L_FRAME48k, sub( Q11, Q_input ) ); + Copy_Scale_sig_16_32( synth_16_fx[n], synth_32_fx[n], L_FRAME48k, sub( Q11, Q_synth_fx ) ); IF( hBWE_FD != NULL ) { - Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, Q11 - hBWE_FD->old_wtda_swb_fx_exp ); + Copy_Scale_sig_16_32( hBWE_FD->L_old_wtda_swb_fx, hBWE_FD->L_old_wtda_swb_fx32, L_FRAME48k, sub( Q11, hBWE_FD->old_wtda_swb_fx_exp ) ); } IF( st->hBWE_TD != NULL ) { - Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, Q11 - st->prev_Qx ); + Copy_Scale_sig_16_32( st->hBWE_TD->old_tbe_synth_fx, st->hBWE_TD->old_tbe_synth_fx_32, L_SHB_TRANSITION_LENGTH, sub( Q11, st->prev_Qx ) ); } /*---------------------------------------------------------------------* @@ -913,7 +1102,7 @@ ivas_error ivas_core_dec( test(); test(); test(); - IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && GT_16( st->bws_cnt, 0 ) ) ) + IF( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) || ( NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) && GE_32( st->core_brate, SID_2k40 ) && EQ_16( st->core, ACELP_CORE ) && !st->con_tcx && GE_32( output_Fs, 32000 ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 ) ) { /* SWB TBE decoder */ Q_white_exc = 0; @@ -921,11 +1110,11 @@ ivas_error ivas_core_dec( ivas_swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); - Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, st->prev_Qx - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_TD->old_tbe_synth_fx_32, st->hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( st->prev_Qx, Q11 ) ); IF( GT_16( Q_white_exc, 31 ) ) { - Scale_sig( tmp_buffer_fx, L_FRAME48k, 31 - Q_white_exc ); + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); Q_white_exc = 31; move16(); } @@ -936,14 +1125,14 @@ ivas_error ivas_core_dec( fb_tbe_dec_ivas_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); } } - ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && EQ_16( st->core, ACELP_CORE ) && GT_16( st->bwidth, NB ) && GT_16( st->bws_cnt, 0 ) && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) + ELSE IF( EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) || ( GE_32( output_Fs, 32000 ) && EQ_16( st->core, ACELP_CORE ) && GT_16( st->bwidth, NB ) && st->bws_cnt > 0 && !st->ppp_mode_dec && !( EQ_16( st->nelp_mode_dec, 1 ) && EQ_16( st->bfi, 1 ) ) ) ) { /* SWB BWE decoder */ Q_syn_hb = swb_bwe_dec_fx32( st, output_32_fx[n], synth_32_fx[n], hb_synth_32_fx[n], use_cldfb_for_dft, output_frame ); - Scale_sig32( hb_synth_32_fx[n], output_frame, Q11 - Q_syn_hb ); + Scale_sig32( hb_synth_32_fx[n], output_frame, sub( Q11, Q_syn_hb ) ); - Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, hBWE_FD->old_wtda_swb_fx_exp - Q11 ); + Copy_Scale_sig_32_16( st->hBWE_FD->L_old_wtda_swb_fx32, st->hBWE_FD->L_old_wtda_swb_fx, output_frame, sub( hBWE_FD->old_wtda_swb_fx_exp, Q11 ) ); } /*---------------------------------------------------------------------* @@ -981,46 +1170,62 @@ ivas_error ivas_core_dec( * SWB CNG *---------------------------------------------------------------------*/ - IF( ( output_frame >= L_FRAME32k && st->hTdCngDec != NULL ) || ( st->element_mode == IVAS_CPE_DFT && st->bwidth >= SWB && st->hTdCngDec != NULL ) ) + test(); + test(); + test(); + test(); + IF( ( GE_16( output_frame, L_FRAME32k ) && st->hTdCngDec != NULL ) || ( EQ_16( st->element_mode, IVAS_CPE_DFT ) && GE_16( st->bwidth, SWB ) && st->hTdCngDec != NULL ) ) { /* SHB CNG decoder */ Word16 synth_fxl[960]; /* Q-2 */ - Word16 q = 2; - Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, -( Q11 + q ) ); + Word16 q; + + q = 2; + move16(); + Copy_Scale_sig_32_16( hb_synth_32_fx[n], hb_synth_16_fx[n], L_FRAME48k, negate( add( Q11, q ) ) ); #ifdef MSAN_FIX - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, -( Q11 + q ) ); + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, output_frame, negate( add( Q11, q ) ) ); #else - Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, -( Q11 + q ) ); + Copy_Scale_sig_32_16( synth_32_fx[n], synth_fxl, L_FRAME48k, negate( add( Q11, q ) ) ); #endif - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, ( Q8 - st->prev_Q_bwe_syn ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, ( st->prev_Q_bwe_syn2 - Q11 ) ); - Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, 2 * ALLPASSSECTIONS_STEEP, ( st->prev_Q_bwe_syn2 - Q11 ) ); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, sub( Q8, st->prev_Q_bwe_syn ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, sub( st->prev_Q_bwe_syn2, Q11 ) ); + Copy_Scale_sig_32_16( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, imult1616( 2, ALLPASSSECTIONS_STEEP ), sub( st->prev_Q_bwe_syn2, Q11 ) ); - swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], -q ); + swb_CNG_dec_ivas_fx( st, synth_fxl, hb_synth_16_fx[n], sid_bw[n], negate( q ) ); - Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); - Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, ( Q11 + q ) ); - Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, -( Q8 - st->prev_Q_bwe_syn ) ); - Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, -( st->prev_Q_bwe_syn2 - Q11 ) ); - Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, 2 * ALLPASSSECTIONS_STEEP, -( st->prev_Q_bwe_syn2 - Q11 ) ); + Copy_Scale_sig_16_32( hb_synth_16_fx[n], hb_synth_32_fx[n], L_FRAME48k, add( Q11, q ) ); + Copy_Scale_sig_16_32( synth_fxl, synth_32_fx[n], L_FRAME48k, add( Q11, q ) ); + Scale_sig( st->hBWE_TD->state_lpc_syn_fx, LPC_SHB_ORDER, negate( sub( Q8, st->prev_Q_bwe_syn ) ) ); + Scale_sig32( st->hBWE_TD->genSHBsynth_Hilbert_Mem_fx, HILBERT_MEM_SIZE, negate( sub( st->prev_Q_bwe_syn2, Q11 ) ) ); + Copy_Scale_sig_16_32( st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st->hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx_32, imult1616( 2, ALLPASSSECTIONS_STEEP ), negate( sub( st->prev_Q_bwe_syn2, Q11 ) ) ); } /*-------------------------------------------------------------------* * Inter-channel BWE decoding *-------------------------------------------------------------------*/ test(); - IF( EQ_16( n, 0 ) && GE_16( st->element_mode, IVAS_CPE_DFT ) ) + IF( n == 0 && GE_16( st->element_mode, IVAS_CPE_DFT ) ) { - Word16 q = 11; + Word16 q; + q = 11; + move16(); - if ( hCPE->hStereoDft != NULL ) + IF( hCPE->hStereoDft != NULL ) { hCPE->hStereoDft->td_gain_fx[0] = 1; + move32(); } - Scale_sig( tmp_buffer_fx, L_FRAME48k, Q11 - Q_white_exc ); + Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( Q11, Q_white_exc ) ); stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q ); #ifdef MSAN_FIX - IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && NE_16( hCPE->hCoreCoder[0]->tdm_LRTD_flag, 0 ) ) ) ) ) ) ) ) + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( GT_32( st->core_brate, SID_2k40 ) && ( !( ( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) || ( ( NE_16( st->core, ACELP_CORE ) || EQ_16( st->extl, -1 ) ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && hCPE->hCoreCoder[0]->tdm_LRTD_flag != 0 ) ) ) ) ) ) ) { Scale_sig32( hb_synth_32_fx[0], output_frame, sub( Q11, q ) ); Scale_sig32( hb_synth_32_fx[1], output_frame, sub( Q11, q ) ); @@ -1037,15 +1242,24 @@ ivas_error ivas_core_dec( * BFI waveform adjustment *----------------------------------------------------------------*/ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( EQ_16( st->core, ACELP_CORE ) && !st->bfi && st->prev_bfi && GE_32( st->last_total_brate, HQ_48k ) && EQ_16( st->last_codec_mode, MODE2 ) && ( EQ_16( st->last_core_bfi, TCX_20_CORE ) || EQ_16( st->last_core_bfi, TCX_10_CORE ) ) && EQ_16( st->hPlcInfo->concealment_method, TCX_NONTONAL ) && LT_16( st->hPlcInfo->nbLostCmpt, 4 ) ) { tmps = NS2SA_fx2( output_Fs, DELAY_CLDFB_NS ); waveform_adj2_fix( st->hTonalMDCTConc->secondLastPcmOut, synth_16_fx[n] + tmps, st->plcInfo.data_noise, &st->plcInfo.outx_new_n1_fx, &st->plcInfo.nsapp_gain_fx, &st->plcInfo.nsapp_gain_n_fx, &st->plcInfo.recovery_gain, st->plcInfo.step_concealgain_fx, - st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, st->hPlcInfo->nbLostCmpt + 1, st->bfi ); + st->plcInfo.Pitch_fx, st->plcInfo.FrameSize, tmps, add( st->hPlcInfo->nbLostCmpt, 1 ), st->bfi ); st->hPlcInfo->Pitch = 0; + move16(); } } @@ -1057,7 +1271,7 @@ ivas_error ivas_core_dec( test(); test(); test(); - IF( ( NE_16( st->extl, -1 ) && ( NE_16( st->extl, IGF_BWE ) || EQ_16( st->last_core, ACELP_CORE ) ) ) || ( GT_16( st->bws_cnt, 0 ) && EQ_16( st->core, ACELP_CORE ) ) ) + IF( ( NE_16( st->extl, -1 ) && ( NE_16( st->extl, IGF_BWE ) || EQ_16( st->last_core, ACELP_CORE ) ) ) || ( st->bws_cnt > 0 && EQ_16( st->core, ACELP_CORE ) ) ) { /* Calculate an additional delay of extension layer components to be synchronized with ACELP synthesis */ IF( EQ_16( st->L_frame, L_FRAME ) ) @@ -1067,6 +1281,7 @@ ivas_error ivas_core_dec( } ELSE { + test(); IF( EQ_16( st->extl, SWB_BWE_HIGHRATE ) || EQ_16( st->extl, FB_BWE_HIGHRATE ) ) { /* HR SWB BWE on top of ACELP@16kHz */ @@ -1089,12 +1304,13 @@ ivas_error ivas_core_dec( test(); test(); test(); - + test(); + test(); IF( !( ( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) && EQ_16( st->last_core, ACELP_CORE ) ) && ( NE_16( st->extl, st->last_extl ) || ( EQ_16( st->extl, st->last_extl ) && ( st->core ^ st->last_core ) == HQ_CORE ) ) && !( EQ_16( st->extl, SWB_CNG ) && EQ_16( st->last_extl, SWB_TBE ) ) && ( NE_16( st->element_mode, IVAS_CPE_TD ) || ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) && tdm_LRTD_flag ) ) ) { /* switching between BWE and TBE technologies */ - incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) @@ -1110,13 +1326,15 @@ ivas_error ivas_core_dec( { /* the previous frame was TBE on top of ACELP@16kHz and the current frame is TBE on top of ACELP@12.8kHz */ - incr = idiv1616( L_FRAME * 2, add( shl( tmps, 1 ), 1 ) ); + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( tmps, 1 ), 1 ) ); tmp16 = 0; move16(); FOR( i = 0; i < tmps; i++ ) { - tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16] ), 1 ) ) ); + tmp_buffer_fx[i] = round_fx( L_add( L_shr( L_mult( st->hb_prev_synth_buffer_fx[i], sin_table256_fx[255 - tmp16] ), 1 ), L_shr( L_mult( st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16] ), 1 ) ) ); + move16(); tmp_buffer_fx[i] = shl_sat( tmp_buffer_fx[i], 1 ); + move16(); tmp16 = add( tmp16, incr ); } Copy( tmp_buffer_fx, st->hb_prev_synth_buffer_fx, tmps ); @@ -1124,7 +1342,7 @@ ivas_error ivas_core_dec( ELSE IF( GT_16( tmps, st->old_bwe_delay ) ) { /* the previous frame was TBE on top of ACELP@12.8kHz and the current frame is TBE on top of ACELP@16kHz */ - incr = idiv1616( L_FRAME * 2, add( shl( st->old_bwe_delay, 1 ), 1 ) ); + incr = idiv1616( imult1616( L_FRAME, 2 ), add( shl( st->old_bwe_delay, 1 ), 1 ) ); tmp16 = 0; move16(); FOR( i = 0; i < st->old_bwe_delay; i++ ) @@ -1139,9 +1357,11 @@ ivas_error ivas_core_dec( move16(); } tmp16 = 0; + move16(); FOR( i = 0; i < st->old_bwe_delay; i++ ) { - tmp_buffer_fx[tmps - 1 - i] = round_fx( L_mac( L_mult( tmp_buffer_fx[tmps - 1 - i], 32767 ), st->hb_prev_synth_buffer_fx[st->old_bwe_delay - 1 - i], sin_table256_fx[tmp16 /*i * incr*/] ) ); + tmp_buffer_fx[sub( sub( tmps, 1 ), i )] = round_fx( L_mac( L_mult( tmp_buffer_fx[sub( sub( tmps, 1 ), i )], 32767 ), st->hb_prev_synth_buffer_fx[sub( sub( st->old_bwe_delay, 1 ), i )], sin_table256_fx[tmp16 /*i * incr*/] ) ); + move16(); tmp16 = add( tmp16, incr ); } @@ -1158,11 +1378,11 @@ ivas_error ivas_core_dec( Copy_Scale_sig_16_32( st->hb_prev_synth_buffer_fx, hb_prev_synth_buffer_fx_32, 111, 11 ); delay_signal_fx( hb_synth_32_fx[n], output_frame, hb_prev_synth_buffer_fx_32, tmps ); - Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, -11 ); + Copy_Scale_sig_32_16( hb_prev_synth_buffer_fx_32, st->hb_prev_synth_buffer_fx, 111, negate( 11 ) ); } ELSE { - Copy_Scale_sig_32_16( hb_synth_32_fx[n] + output_frame - tmps, st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); + Copy_Scale_sig_32_16( hb_synth_32_fx[n] + sub( output_frame, tmps ), st->hb_prev_synth_buffer_fx, tmps, negate( Q11 ) ); } st->old_bwe_delay = tmps; @@ -1174,25 +1394,30 @@ ivas_error ivas_core_dec( IF( GE_16( output_frame, L_FRAME32k ) && GT_16( st->extl, SWB_CNG ) && EQ_16( st->core, ACELP_CORE ) && st->hTdCngDec != NULL ) { Word16 exp, fra; + Word16 gb; SWITCH( output_frame ) { case L_FRAME8k: tmp16 = 205; + move16(); BREAK; /*Q15*/ case L_FRAME16k: tmp16 = 102; + move16(); BREAK; /*Q15*/ case L_FRAME32k: tmp16 = 51; + move16(); BREAK; /*Q15*/ case L_FRAME48k: tmp16 = 34; + move16(); BREAK; /*Q15*/ } L_tmp = L_deposit_l( 2 ); /*0.001 in Q11*/ - Word16 gb = find_guarded_bits_fx( output_frame ); + gb = find_guarded_bits_fx( output_frame ); L_tmp = L_add( L_tmp, sum2_f_32_fx( hb_synth_32_fx[n], output_frame, sub( 11, gb ) ) ); L_tmp = Mpy_32_16_1( L_tmp, tmp16 ); exp = norm_l( L_tmp ); @@ -1224,8 +1449,8 @@ ivas_error ivas_core_dec( { if ( hCPE->hCoreCoder[ch_ind]->hHQ_core != NULL ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ch_ind]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ch_ind]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ch_ind]->hHQ_core->Q_old_wtda ) ); } } } @@ -1236,18 +1461,20 @@ ivas_error ivas_core_dec( { if ( hSCE->hCoreCoder[0]->hHQ_core != NULL ) { - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); - Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hSCE->hCoreCoder[0]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); + Copy_Scale_sig_16_32( hSCE->hCoreCoder[0]->hHQ_core->old_out_fx, hSCE->hCoreCoder[0]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hSCE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); } } } - Word16 exp_max = 0; + Word16 exp_max; Word32 output_fx_loc[L_FRAME48k]; + exp_max = 0; + move16(); IF( NE_16( st->element_mode, IVAS_CPE_DFT ) ) { - + test(); IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) || sba_dirac_stereo_flag ) { ivas_post_proc_fx( hSCE, hCPE, n, synth_32_fx[n], NULL, output_frame, sba_dirac_stereo_flag ); @@ -1264,7 +1491,9 @@ ivas_error ivas_core_dec( } ELSE /* IVAS_CPE_DFT */ { - Word16 q = 11; + Word16 q; + q = 11; + move16(); IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_MDCT ) ) { stereo_mdct2dft_update_fx( hCPE, output_32_fx[0], synth_32_fx[0] ); @@ -1281,6 +1510,7 @@ ivas_error ivas_core_dec( Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_DFT[1] ) ); } + test(); IF( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) { /* mono output for non-residual coding modes uses CLDFB instead of DFT - requires DFT buffer update in case of bitrate switching */ @@ -1303,53 +1533,50 @@ ivas_error ivas_core_dec( test(); IF( ( EQ_16( st->codec_mode, MODE1 ) && st->hTcxDec != NULL ) && ( ( EQ_16( st->core, ACELP_CORE ) && !( EQ_16( st->bfi, 1 ) && EQ_16( st->con_tcx, 1 ) ) ) || EQ_16( st->core, HQ_CORE ) ) ) { - Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0 /*, temp = 0*/; - move16(); + Word16 exp_prev_synth_buffer = 0, exp_old_out = 0, exp_delay_buf_out = 0, exp_ouput = 0, exp_synth_history = 0; move16(); move16(); move16(); move16(); move16(); - Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), -11 ); + Copy_Scale_sig32_16( st->prev_synth_buffer32_fx, st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), negate( Q11 ) ); st->q_prev_synth_buffer_fx = 0; + move16(); exp_ouput = Find_Max_Norm32( output_32_fx[n], output_frame ); - exp_ouput += 11; + exp_ouput = add( exp_ouput, Q11 ); exp_prev_synth_buffer = Find_Max_Norm16( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ) ); - exp_prev_synth_buffer += st->q_prev_synth_buffer_fx; - exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) + NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) - NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ); + exp_prev_synth_buffer = add( exp_prev_synth_buffer, st->q_prev_synth_buffer_fx ); + exp_old_out = Find_Max_Norm16( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( add( NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ) ); exp_delay_buf_out = Find_Max_Norm16( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ); - exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ) + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) - output_frame ); + exp_synth_history = Find_Max_Norm16( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ) ); #ifndef FIX_740_HQ_CORE_OVA exp_synth_history += st->hTcxDec->q_synth_history_fx; #endif exp_max = s_min( exp_synth_history, exp_ouput ); exp_max = s_min( exp_max, exp_prev_synth_buffer ); - move16(); exp_max = s_min( exp_max, exp_old_out ); - move16(); exp_max = s_min( exp_max, exp_delay_buf_out ); - move16(); Copy32( output_32_fx[n], output_fx_loc, output_frame ); - Scale_sig32( output_fx_loc, output_frame, exp_max - 11 ); - Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max - 0 ); - Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ) - NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), exp_max - 0 ); - Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, DELAY_BWE_TOTAL_NS - DELAY_CLDFB_NS ), exp_max - st->q_prev_synth_buffer_fx ); - Scale_sig( st->hTcxDec->synth_history_fx + output_frame, 2 * output_frame - NS2SA( st->output_Fs, DELAY_CLDFB_NS ) + NS2SA( st->output_Fs, PH_ECU_MEM_NS ) - output_frame, exp_max - st->Q_syn ); + Scale_sig32( output_fx_loc, output_frame, sub( exp_max, Q11 ) ); + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), exp_max ); + Scale_sig( st->hHQ_core->old_out_fx + NS2SA( st->output_Fs, N_ZERO_MDCT_NS ), sub( NS2SA( st->output_Fs, PH_ECU_LOOKAHEAD_NS ), NS2SA( st->output_Fs, N_ZERO_MDCT_NS ) ), exp_max ); + Scale_sig( st->prev_synth_buffer_fx, NS2SA( 48000, L_sub( DELAY_BWE_TOTAL_NS, DELAY_CLDFB_NS ) ), sub( exp_max, st->q_prev_synth_buffer_fx ) ); + Scale_sig( st->hTcxDec->synth_history_fx + output_frame, sub( add( sub( imult1616( 2, output_frame ), NS2SA( st->output_Fs, DELAY_CLDFB_NS ) ), NS2SA( st->output_Fs, PH_ECU_MEM_NS ) ), output_frame ), sub( exp_max, st->Q_syn ) ); - st->q_prev_synth_buffer_fx = exp_max - st->q_prev_synth_buffer_fx; + st->q_prev_synth_buffer_fx = sub( exp_max, st->q_prev_synth_buffer_fx ); } /* Save synthesis for HQ FEC */ save_synthesis_hq_fec_fx( st, output_fx_loc, output_frame, hCPE ); /* Updates */ - ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], 11 ); + ivas_updt_dec_common_fx( st, NORMAL_HQ_CORE, -1, output_32_fx[n], Q11 ); - Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), -exp_max ); + Scale_sig( st->delay_buf_out_fx, NS2SA( st->output_Fs, DELAY_CLDFB_NS ), negate( exp_max ) ); } /* n_channels loop */ @@ -1360,11 +1587,13 @@ ivas_error ivas_core_dec( { scale_sig32( st->cldfbAna->cldfb_state_fx, st->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); st->cldfbAna->Q_cldfb_state = Q11; + move16(); } IF( st->cldfbSynHB ) { scale_sig32( st->cldfbSynHB->cldfb_state_fx, st->cldfbSynHB->cldfb_size, sub( Q11, Q10 ) ); st->cldfbSynHB->Q_cldfb_state = Q11; + move16(); } } diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 862ecaa11..ccb39cadf 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -35,6 +35,7 @@ #include "ivas_prot.h" #ifdef IVAS_FLOAT_FIXED #include "ivas_prot_fx.h" +#include "prot_fx1.h" #include "prot_fx2.h" #endif // IVAS_FLOAT_FIXED #include "prot.h" @@ -150,14 +151,22 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* prepare bitstream buffers */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - move32(); + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + ELSE + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } } } IF( GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = mct_dec_reconfigure_fx( st_ivas, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = mct_dec_reconfigure_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -165,7 +174,14 @@ ivas_error ivas_corecoder_dec_reconfig_fx( } ELSE { - st0 = GT_16( nSCE_old, 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; + IF( nSCE_old > 0 ) + { + st0 = st_ivas->hSCE[0]->hCoreCoder[0]; + } + ELSE + { + st0 = st_ivas->hCPE[0]->hCoreCoder[0]; + } prev_bfi = st0->prev_bfi; move16(); nSCE_existing = s_min( nSCE_old, st_ivas->nSCE ); @@ -180,9 +196,9 @@ ivas_error ivas_corecoder_dec_reconfig_fx( test(); test(); - IF( sba_dirac_stereo_flag_old && EQ_16( nCPE_old, 0 ) && st_ivas->hCPE[0] ) + IF( sba_dirac_stereo_flag_old && ( nCPE_old == 0 ) && st_ivas->hCPE[0] ) { - st_ivas->hCPE[0]->hCoreCoder[0] = 0; /* this has been deallocated as part of the SCE it actually belongs to */ + st_ivas->hCPE[0]->hCoreCoder[0] = NULL; /* this has been deallocated as part of the SCE it actually belongs to */ destroy_cpe_dec( st_ivas->hCPE[0] ); st_ivas->hCPE[0] = NULL; } @@ -192,7 +208,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* don't deallocate first CPE in case of mono/stereo output of 1 TC SBA, only deallocate core coder */ test(); test(); - IF( EQ_16( cpe_id, 0 ) && st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old ) + IF( ( cpe_id == 0 ) && st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old ) { FOR( n = 0; n < CPE_CHANNELS; n++ ) { @@ -248,7 +264,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( } FOR( ; sce_id < st_ivas->nSCE; sce_id++ ) { - IF( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_sce_dec( st_ivas, sce_id, brate_SCE ) ), IVAS_ERR_OK ) ) { return error; } @@ -258,7 +274,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( test(); test(); test(); - IF( st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old && EQ_16( st_ivas->nchan_transport, 1 ) && EQ_16( nSCE_old, 0 ) ) + IF( st_ivas->sba_dirac_stereo_flag && sba_dirac_stereo_flag_old && EQ_16( st_ivas->nchan_transport, 1 ) && ( nSCE_old == 0 ) ) { st_ivas->hCPE[0]->hCoreCoder[0] = st_ivas->hSCE[0]->hCoreCoder[0]; /* don't allocate unnecessary core coder, simply point to core coder of SCE element */ st_ivas->hCPE[0]->hCoreCoder[1] = NULL; @@ -272,8 +288,16 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* prepare bitstream buffers */ FOR( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ - move32(); + IF( GT_16( st_ivas->nCPE, 1 ) ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } + ELSE + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = L_shr( st_ivas->hCPE[cpe_id]->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ + move32(); + } } } FOR( ; cpe_id < st_ivas->nCPE; cpe_id++ ) @@ -285,7 +309,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( move16(); } - IF( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_cpe_dec( st_ivas, cpe_id, brate_CPE ) ), IVAS_ERR_OK ) ) { return error; } @@ -307,19 +331,20 @@ ivas_error ivas_corecoder_dec_reconfig_fx( st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate; move32(); st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = extract_l( Mpy_32_16_1( st_ivas->hCPE[0]->element_brate, INV_FRAME_PER_SEC_Q15 ) ); + move16(); st_ivas->hCPE[0]->hCoreCoder[n]->igf = 0; move16(); } } - IF( ( error = create_mct_dec_fx( st_ivas ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = create_mct_dec_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( st_ivas->hMCT != NULL && GT_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = mct_dec_reconfigure_fx( st_ivas, (UWord16) NE_16( st_ivas->nchan_transport, nchan_transport_old ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = mct_dec_reconfigure_fx( st_ivas, (UWord16) NE_16( st_ivas->nchan_transport, nchan_transport_old ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -329,7 +354,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( test(); IF( EQ_16( st_ivas->nCPE, 1 ) && GT_16( nCPE_old, 1 ) ) { - IF( ( st_ivas->hCPE[sub( st_ivas->nCPE, 1 )]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + IF( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) ); } @@ -372,9 +397,9 @@ ivas_error ivas_corecoder_dec_reconfig_fx( ( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && st_ivas->sba_dirac_stereo_flag && !sba_dirac_stereo_flag_old ) ) { /* if at least one CPE is already available, only allocate DFT Stereo struct */ - IF( GT_16( st_ivas->nCPE, 0 ) ) + IF( ( st_ivas->nCPE > 0 ) ) { - IF( ( error = stereo_dft_dec_create_fx( &( st_ivas->hCPE[0]->hStereoDft ), st_ivas->hCPE[0]->element_brate, st_ivas->hDecoderConfig->output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = stereo_dft_dec_create_fx( &( st_ivas->hCPE[0]->hStereoDft ), st_ivas->hCPE[0]->element_brate, st_ivas->hDecoderConfig->output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) ) { return error; } @@ -382,7 +407,9 @@ ivas_error ivas_corecoder_dec_reconfig_fx( /* otherwise create extra dummy CPE */ ELSE { - IF( ( error = create_cpe_dec( st_ivas, 0, ivas_total_brate / ( st_ivas->nSCE + st_ivas->nCPE ) ) ) != IVAS_ERR_OK ) + Word32 quo, rem; + iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nSCE, st_ivas->nCPE ), &quo, &rem, 0 ); + IF( NE_32( ( error = create_cpe_dec( st_ivas, 0, quo ) ), IVAS_ERR_OK ) ) { return error; } @@ -401,7 +428,6 @@ ivas_error ivas_corecoder_dec_reconfig_fx( } set32_fx( st_ivas->hSCE[0]->save_synth_fx, 0, output_frame ); st_ivas->hSCE[0]->q_save_synth_fx = 0; - // st_ivas->hSCE[0]->q_save_synth_fx = Q11; move16(); } @@ -429,7 +455,7 @@ ivas_error ivas_corecoder_dec_reconfig_fx( test(); IF( LE_32( hDecoderConfig->last_ivas_total_brate, IVAS_SID_5k2 ) && GE_16( st_ivas->nCPE, 1 ) ) { - IF( ( error = initMdctStereoDtxData_fx( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = initMdctStereoDtxData_fx( st_ivas->hCPE[0] ) ), IVAS_ERR_OK ) ) { return error; } @@ -778,6 +804,7 @@ ivas_error ivas_hp20_dec_reconfig_fx( ivas_error error; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * HP20 memories @@ -946,10 +973,13 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* special case, if there was one transport channel in the previous frame and more than one in the current frame, remove the second CLDFB here, it was for CNA/CNG */ + test(); + test(); + test(); IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( nchan_transport_old, 1 ) && EQ_16( numCldfbAnalyses_old, 2 ) && GT_16( st_ivas->nchan_transport, 1 ) ) { deleteCldfb_ivas( &( st_ivas->cldfbAnaDec[1] ) ); - numCldfbAnalyses_old--; + numCldfbAnalyses_old = sub( numCldfbAnalyses_old, 1 ); } /* resample CLDFB analysis instances */ FOR( i = 0; i < min( numCldfbAnalyses, numCldfbAnalyses_old ); i++ ) @@ -974,7 +1004,7 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* create additional CLDFB synthesis instances */ FOR( i = numCldfbAnalyses_old; i < numCldfbAnalyses; i++ ) { - IF( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbAnaDec[i] ), CLDFB_ANALYSIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } @@ -994,22 +1024,35 @@ ivas_error ivas_cldfb_dec_reconfig_fx( /* create additional CLDFB synthesis instances */ FOR( i = numCldfbSyntheses_old; i < numCldfbSyntheses; i++ ) { - IF( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = openCldfb_ivas_fx( &( st_ivas->cldfbSynDec[i] ), CLDFB_SYNTHESIS, hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS ) ), IVAS_ERR_OK ) ) { return error; } } } /* CLDFB Interpolation weights */ - IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( NE_16( numCldfbAnalyses_old, numCldfbAnalyses ) || NE_16( numCldfbSyntheses_old, numCldfbSyntheses ) || NE_16( nchan_transport_old, st_ivas->nchan_transport ) ) && NE_16( numCldfbAnalyses, 0 ) && NE_16( numCldfbSyntheses, 0 ) ) + test(); + test(); + test(); + test(); + test(); + IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( NE_16( numCldfbAnalyses_old, numCldfbAnalyses ) || NE_16( numCldfbSyntheses_old, numCldfbSyntheses ) || NE_16( nchan_transport_old, st_ivas->nchan_transport ) ) && ( numCldfbAnalyses != 0 ) && ( numCldfbSyntheses != 0 ) ) { ivas_spar_get_cldfb_gains_fx( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); FOR( i = 0; i < st_ivas->cldfbAnaDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], 16 ); // Scaling down from 27 to 11 + { + st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbAnaDec[0]->cldfb_state_fx[i], sub( Q27, Q11 ) ); // Scaling down from 27 to 11 + move32(); + } st_ivas->cldfbAnaDec[0]->Q_cldfb_state = Q11; + move16(); FOR( i = 0; i < st_ivas->cldfbSynDec[0]->cldfb_state_length; i++ ) - st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], 21 - 11 ); // Scaling down from 21 to 11 + { + st_ivas->cldfbSynDec[0]->cldfb_state_fx[i] = L_shr( st_ivas->cldfbSynDec[0]->cldfb_state_fx[i], sub( Q21, Q11 ) ); // Scaling down from 21 to 11 + move32(); + } st_ivas->cldfbSynDec[0]->Q_cldfb_state = Q11; + move16(); } return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_cpe_dec_fx.c b/lib_dec/ivas_cpe_dec_fx.c index 713bf6841..e0ac57446 100644 --- a/lib_dec/ivas_cpe_dec_fx.c +++ b/lib_dec/ivas_cpe_dec_fx.c @@ -78,7 +78,7 @@ ivas_error ivas_cpe_dec_fx( Word16 last_bwidth; Word16 tdm_ratio_idx; Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ /* Q11 */ - Word16 q_res_buf = Q8; + Word16 q_res_buf; Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */ CPE_DEC_HANDLE hCPE; Decoder_State **sts; @@ -86,8 +86,12 @@ ivas_error ivas_cpe_dec_fx( ivas_error error; Word32 cpe_brate; Word32 element_brate_ref; + Word32 quo, rem; error = IVAS_ERR_OK; + move32(); + q_res_buf = Q8; + move16(); push_wmops( "ivas_cpe_dec" ); @@ -121,29 +125,34 @@ ivas_error ivas_cpe_dec_fx( *----------------------------------------------------------------*/ #if 1 // Float to fix conversions - Word16 q_old_out_LB = 31; + Word16 q_old_out_LB; + q_old_out_LB = 31; + move16(); // q_output_mem = 11; // q_buff_LBTCX_mem = 11; // q_input_mem_LB = q_buff_LBTCX_mem; FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { + test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, Q11 - hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); } } q_old_out_LB = Q11; + move16(); FOR( Word16 ind1 = 0; ind1 < 1; ind1++ ) { IF( hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, L_FRAME32k, Q11 - hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = q_old_out_LB; + move16(); } } #endif // Float to fix conversions - IF( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) ) { return error; } @@ -152,14 +161,15 @@ ivas_error ivas_cpe_dec_fx( { IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda - Q11 ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->oldOut_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda, Q11 ) ); } } FOR( Word16 ind1 = 0; ind1 < 2; ind1++ ) { + test(); IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core ) { - Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB - Q11 ); + Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_outLB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); } } #endif @@ -170,7 +180,7 @@ ivas_error ivas_cpe_dec_fx( n_channels = CPE_CHANNELS; move16(); - IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) + if ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { n_channels = 1; /* in DFT stereo, only M channel is coded */ move16(); @@ -186,7 +196,7 @@ ivas_error ivas_cpe_dec_fx( sts[n]->element_mode = hCPE->element_mode; move16(); - IF( !st_ivas->bfi ) + if ( !st_ivas->bfi ) { sts[n]->tdm_LRTD_flag = 0; move16(); @@ -225,18 +235,27 @@ ivas_error ivas_cpe_dec_fx( test(); test(); test(); - IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || EQ_16( sts[0]->ini_frame, 0 ) || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) ) + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || sts[0]->ini_frame == 0 || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) ) { + STEREO_DFT_CONFIG_DATA_HANDLE hConfig; + IF( hCPE->hStereoDft == NULL ) + { + hConfig = NULL; + } + ELSE + { + hConfig = hCPE->hStereoDft->hConfig; + } test(); IF( st_ivas->hQMetaData != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, (Word32) ( st_ivas->hQMetaData->bits_frame_nominal * 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } ELSE { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } ELSE @@ -244,11 +263,11 @@ ivas_error ivas_cpe_dec_fx( /* Note: This only works for stereo operation. If DTX would be applied for multiple CPEs a different bitrate signaling is needed */ IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } ELSE { - stereo_dft_config_fx( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); + stereo_dft_config_fx( hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } } } @@ -257,8 +276,9 @@ ivas_error ivas_cpe_dec_fx( { IF( hCPE->hStereoTD->tdm_LRTD_flag ) { - sts[0]->bits_frame_nominal = extract_l( L_shr( hCPE->element_brate, 1 ) / FRAMES_PER_SEC ); - sts[1]->bits_frame_nominal = extract_l( L_shr( hCPE->element_brate, 1 ) / FRAMES_PER_SEC ); + iDiv_and_mod_32( L_shr( hCPE->element_brate, 1 ), FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[0]->bits_frame_nominal = extract_l( quo ); + sts[1]->bits_frame_nominal = extract_l( quo ); } ELSE { @@ -278,7 +298,8 @@ ivas_error ivas_cpe_dec_fx( /* Update DFT Stereo memories */ stereo_dft_dec_update_fx( hCPE->hStereoDft, output_frame, 0 ); - IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) && LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LE_32( ivas_total_brate, IVAS_SID_5k2 ) ) { IF( EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) { @@ -300,12 +321,23 @@ ivas_error ivas_cpe_dec_fx( move32(); IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { - sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( (Word16) ( cpe_brate / FRAMES_PER_SEC ), 1 ), nb_bits_metadata ); - sts[1]->bit_stream = sts[1]->bit_stream + (Word16) ( hCPE->brate_surplus / FRAMES_PER_SEC ); + iDiv_and_mod_32( cpe_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata ); + IF( hCPE->brate_surplus < 0 ) + { + iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + } + ELSE + { + iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + } + sts[1]->bit_stream = sts[1]->bit_stream + extract_l( quo ); } ELSE { - sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( (Word16) ( ivas_total_brate / FRAMES_PER_SEC ), 1 ), nb_bits_metadata ); + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata ); } IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) ) @@ -331,9 +363,11 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { nb_bits = sub( nb_bits, nb_bits_metadata ); - IF( LT_32( hCPE->brate_surplus, 0 ) ) + IF( hCPE->brate_surplus < 0 ) { - nb_bits = add( nb_bits, extract_l( hCPE->brate_surplus / FRAMES_PER_SEC ) ); + iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + nb_bits = add( nb_bits, extract_l( quo ) ); } } @@ -341,7 +375,7 @@ ivas_error ivas_cpe_dec_fx( } /* subtract metadata bitbudget */ - sts[0]->total_brate = L_sub( sts[0]->total_brate, nb_bits_metadata * FRAMES_PER_SEC ); + sts[0]->total_brate = L_sub( sts[0]->total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); /* subtract bit-rate for combined format coding */ test(); @@ -363,8 +397,18 @@ ivas_error ivas_cpe_dec_fx( /* signal bitrate for BW selection in the SCh */ sts[0]->bits_frame_channel = 0; move16(); - sts[1]->bits_frame_channel = extract_l( hCPE->element_brate / FRAMES_PER_SEC ); - sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( hCPE->brate_surplus / FRAMES_PER_SEC ) ); + iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[1]->bits_frame_channel = extract_l( quo ); + IF( hCPE->brate_surplus < 0 ) + { + iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + } + ELSE + { + iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + } + sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( quo ) ); IF( st_ivas->hQMetaData != NULL ) { sts[1]->bits_frame_channel = sub( sts[1]->bits_frame_channel, st_ivas->hQMetaData->metadata_max_bits ); @@ -378,7 +422,16 @@ ivas_error ivas_cpe_dec_fx( test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - brate_surplus[0] = L_shr( L_mult( (Word16) L_shr( ( hCPE->brate_surplus / FRAMES_PER_SEC ), 1 ), FRAMES_PER_SEC ), 1 ); + IF( hCPE->brate_surplus < 0 ) + { + iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + } + ELSE + { + iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 ); + } + brate_surplus[0] = L_shr( L_mult( extract_l( L_shr( quo, 1 ) ), FRAMES_PER_SEC ), 1 ); move32(); brate_surplus[1] = L_sub( hCPE->brate_surplus, brate_surplus[0] ); move32(); @@ -386,9 +439,9 @@ ivas_error ivas_cpe_dec_fx( test(); test(); - IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && ( EQ_16( sts[0]->first_CNG, 0 ) || EQ_16( sts[1]->first_CNG, 0 ) ) ) + IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && ( sts[0]->first_CNG == 0 || sts[1]->first_CNG == 0 ) ) { - IF( ( error = initMdctStereoDtxData_fx( hCPE ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = initMdctStereoDtxData_fx( hCPE ) ), IVAS_ERR_OK ) ) { return error; } @@ -409,15 +462,26 @@ ivas_error ivas_cpe_dec_fx( sts[n]->total_brate = hCPE->element_brate; move32(); } - sts[n]->bits_frame_nominal = extract_l( sts[n]->total_brate / FRAMES_PER_SEC ); - sts[n]->bits_frame_channel = extract_l( L_shr( ( hCPE->element_brate / FRAMES_PER_SEC ), sub( n_channels, 1 ) ) ); + iDiv_and_mod_32( sts[n]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[n]->bits_frame_nominal = extract_l( quo ); + iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[n]->bits_frame_channel = extract_l( L_shr( quo, sub( n_channels, 1 ) ) ); /* subtract bit-rate for combined format coding */ test(); test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { - sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( brate_surplus[n] / FRAMES_PER_SEC ) ); + IF( brate_surplus[n] < 0 ) + { + iDiv_and_mod_32( L_abs( brate_surplus[n] ), FRAMES_PER_SEC, &quo, &rem, 0 ); + quo = L_negate( quo ); + } + ELSE + { + iDiv_and_mod_32( brate_surplus[n], FRAMES_PER_SEC, &quo, &rem, 0 ); + } + sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( quo ) ); sts[n]->total_brate = L_add( sts[n]->total_brate, brate_surplus[n] ); } } @@ -447,7 +511,14 @@ ivas_error ivas_cpe_dec_fx( FOR( n = 0; n < n_channels; n++ ) { /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */ - sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, ( hCPE->hStereoTD != NULL ? hCPE->hStereoTD->tdm_LRTD_flag : 0 ), sts[n]->bwidth, sts[n]->cng_type ); + IF( hCPE->hStereoTD != NULL ) + { + sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, hCPE->hStereoTD->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type ); + } + ELSE + { + sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, 0, sts[n]->bwidth, sts[n]->cng_type ); + } } FOR( n = 0; n < n_channels; n++ ) @@ -469,7 +540,7 @@ ivas_error ivas_cpe_dec_fx( { sts[n]->VAD = 1; move16(); - sts[n]->active_cnt++; + sts[n]->active_cnt = add( sts[n]->active_cnt, 1 ); sts[n]->active_cnt = s_min( sts[n]->active_cnt, 100 ); } @@ -495,7 +566,8 @@ ivas_error ivas_cpe_dec_fx( { tdm_configure_dec( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata ); - sts[1]->bit_stream = sts[0]->bit_stream + extract_l( sts[0]->total_brate / FRAMES_PER_SEC ); + iDiv_and_mod_32( sts[0]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + sts[1]->bit_stream = sts[0]->bit_stream + extract_l( quo ); } ELSE { @@ -514,7 +586,7 @@ ivas_error ivas_cpe_dec_fx( test(); IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) ) { - IF( ( error = ivas_core_dec( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_core_dec( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -539,7 +611,7 @@ ivas_error ivas_cpe_dec_fx( set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX ); /* core decoder */ - IF( ( error = ivas_core_dec( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_core_dec( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -547,47 +619,73 @@ ivas_error ivas_cpe_dec_fx( // Scaling of DFT's Word16 shift; Word32 tmp1, tmp2; + Word16 shift1, shift2; maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 ); maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 ); - shift = s_min( ( tmp1 == 0 ) ? 31 : norm_l( tmp1 ), ( tmp2 == 0 ) ? 31 : norm_l( tmp2 ) ); + IF( tmp1 == 0 ) + { + shift1 = Q31; + move16(); + } + ELSE + { + shift1 = norm_l( tmp1 ); + } + IF( tmp2 == 0 ) + { + shift2 = Q31; + move16(); + } + ELSE + { + shift2 = norm_l( tmp2 ); + } + shift = s_min( shift1, shift2 ); - IF( shift != 31 ) + IF( NE_16( shift, 31 ) ) { - shift = hCPE->hStereoDft->q_dft + shift - Q13; /* Q13 for guard bits */ + shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q13 ); /* Q13 for guard bits */ - IF( shift > hCPE->hStereoDft->q_dft ) + IF( GT_16( shift, hCPE->hStereoDft->q_dft ) ) { - Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, shift - hCPE->hStereoDft->q_dft ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, shift - hCPE->hStereoDft->q_dft ); + Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); hCPE->hStereoDft->q_dft = shift; + move16(); } } ELSE { hCPE->hStereoDft->q_dft = Q8; + move16(); } /* DFT Stereo residual decoding */ test(); - IF( GT_16( hCPE->hStereoDft->res_cod_band_max, 0 ) && !st_ivas->bfi ) + IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st_ivas->bfi ) { - Word16 q = Q11; + Word16 q; Word16 q_out_DFT[2]; - Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, 2 * NB_SUBFR16k + 2, -10 ); + q = Q11; + move16(); + + Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), negate( Q10 ) ); stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] ); - Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, 2 * NB_SUBFR16k + 2, 10 ); + Copy_Scale_sig_16_32( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, add( imult1616( 2, NB_SUBFR16k ), 2 ), 10 ); - Scale_sig32( output[1], L_FRAME8k, Q11 - Q15 ); // Q15 -> Q11 + Scale_sig32( output[1], L_FRAME8k, sub( Q11, Q15 ) ); // Q15 -> Q11 q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft; + move16(); + move16(); stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT ); - Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, hCPE->hStereoDft->q_dft - q_out_DFT[1] ); + Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); } /* DFT stereo CNG */ @@ -595,6 +693,7 @@ ivas_error ivas_cpe_dec_fx( Word16 q_dft; q_dft = hCPE->hStereoDft->q_dft; + move16(); // TODO : To check this @@ -608,20 +707,25 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; + move16(); FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) { hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; + move16(); } hCPE->hStereoDft->first_frame = 0; + move16(); } scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; + move16(); #endif stereo_dft_unify_dmx_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata ); #if 1 scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q16, hCPE->hStereoDft->q_res_cod_mem_fx ) ); hCPE->hStereoDft->q_res_cod_mem_fx = Q16; + move16(); #endif } ELSE @@ -631,21 +735,26 @@ ivas_error ivas_cpe_dec_fx( IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) ) { hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft; + move16(); FOR( int ii = 0; ii < (int) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ ) { hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft; + move16(); } hCPE->hStereoDft->first_frame = 0; + move16(); } scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft; + move16(); } #endif stereo_dft_dec_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); #if 1 scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q16, hCPE->hStereoDft->q_res_cod_mem_fx ) ); hCPE->hStereoDft->q_res_cod_mem_fx = Q16; + move16(); #endif } @@ -733,7 +842,7 @@ ivas_error ivas_cpe_dec_fx( test(); test(); test(); - IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && ( EQ_16( is_DTXrate( ivas_total_brate ), 0 ) || ( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && EQ_16( is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ), 0 ) ) ) ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && ( is_DTXrate( ivas_total_brate ) == 0 || ( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ) == 0 ) ) ) { applyDmxMdctStereo_fx( hCPE, output, output_frame ); } @@ -809,6 +918,7 @@ ivas_error create_cpe_dec( Word32 cpe_brate; error = IVAS_ERR_OK; + move32(); /*-----------------------------------------------------------------* * Allocate CPE handle @@ -824,13 +934,17 @@ ivas_error create_cpe_dec( *-----------------------------------------------------------------*/ output_Fs = st_ivas->hDecoderConfig->output_Fs; - + move32(); hCPE->cpe_id = cpe_id; - + move16(); hCPE->element_brate = element_brate; + move32(); hCPE->last_element_brate = hCPE->element_brate; + move32(); hCPE->element_mode = st_ivas->element_mode_init; + move16(); hCPE->last_element_mode = st_ivas->element_mode_init; + move16(); hCPE->hStereoDft = NULL; hCPE->hStereoDftDmx = NULL; @@ -841,43 +955,62 @@ ivas_error create_cpe_dec( hCPE->hStereoCng = NULL; hCPE->stereo_switching_counter = 10; + move16(); hCPE->NbFrameMod = 7; + move16(); // hCPE->lt_es_em = 0.0f; hCPE->lt_es_em_fx = 0; + move32(); /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */ + test(); + test(); + test(); IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) ) { hCPE->nchan_out = CPE_CHANNELS; + move16(); } ELSE { hCPE->nchan_out = s_min( CPE_CHANNELS, st_ivas->hDecoderConfig->nchan_out ); } + test(); + test(); + test(); IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) { cpe_brate = element_brate; + move32(); } ELSE { cpe_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); } + test(); + test(); + test(); + test(); IF( ( ( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) || ( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) ) ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) ) { hCPE->nchan_out = 1; + move16(); } FOR( n = 0; n < CPE_CHANNELS; n++ ) { - set32_fx( hCPE->prev_hb_synth_fx[n], 0, NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - DELAY_BWE_TOTAL_NS ) ); - set32_fx( hCPE->prev_synth_fx[n], 0, NS2SA_fx2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ) ); + set32_fx( hCPE->prev_hb_synth_fx[n], 0, NS2SA_fx2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) ); + set32_fx( hCPE->prev_synth_fx[n], 0, NS2SA_fx2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, STEREO_DFT32MS_OVL_NS ) ) ); } hCPE->q_prev_synth_fx = 0; + move16(); hCPE->brate_surplus = 0; + move32(); /*-----------------------------------------------------------------* * DFT stereo I/O Buffers: allocate and initialize @@ -885,6 +1018,11 @@ ivas_error create_cpe_dec( FOR( i = 0; i < CPE_CHANNELS; i++ ) { + test(); + test(); + test(); + test(); + test(); IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) || ( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) && EQ_16( (Word16) st_ivas->mc_mode, MC_MODE_MCMASA ) ) || st_ivas->sba_dirac_stereo_flag ) { @@ -900,7 +1038,7 @@ ivas_error create_cpe_dec( } set32_fx( hCPE->input_mem_LB_fx[i], 0, STEREO_DFT32MS_OVL_16k ); - IF( EQ_16( i, 0 ) ) + IF( i == 0 ) { IF( ( hCPE->input_mem_BPF_fx[0] = (Word32 *) malloc( sizeof( Word32 ) * STEREO_DFT32MS_OVL_16k ) ) == NULL ) { @@ -915,6 +1053,7 @@ ivas_error create_cpe_dec( } set32_fx( hCPE->output_mem_fx[i], 0, NS2SA_fx2( output_Fs, STEREO_DFT32MS_OVL_NS ) ); hCPE->q_output_mem_fx[i] = Q11; + move16(); IF( LT_16( i, hCPE->nchan_out ) ) { IF( ( hCPE->prev_synth_chs_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_fx2( output_Fs, FRAME_SIZE_NS ) ) ) == NULL ) @@ -932,12 +1071,13 @@ ivas_error create_cpe_dec( { hCPE->input_mem_fx[i] = NULL; hCPE->input_mem_LB_fx[i] = NULL; - IF( EQ_16( i, 0 ) ) + IF( i == 0 ) { hCPE->input_mem_BPF_fx[0] = NULL; } hCPE->output_mem_fx[i] = NULL; hCPE->q_output_mem_fx[i] = 0; + move16(); hCPE->prev_synth_chs_fx[i] = NULL; } } @@ -964,10 +1104,13 @@ ivas_error create_cpe_dec( // st->total_brate = hCPE->element_brate / ( CPE_CHANNELS ); st->total_brate = L_shr( hCPE->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ st->mct_chan_mode = MCT_CHAN_MODE_REGULAR; + move32(); st->is_ism_format = 0; + move16(); st->ivas_format = st_ivas->ivas_format; + move32(); - IF( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) ) { return error; } @@ -979,141 +1122,137 @@ ivas_error create_cpe_dec( * DFT stereo initialization *-----------------------------------------------------------------*/ - IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( hCPE->cpe_id, 0 ) ) ){ -#ifdef IVAS_FLOAT_FIXED - IF( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ){ - return error; -} -#else - IF( ( error = stereo_dft_dec_create( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ) != IVAS_ERR_OK ){ + test(); + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && hCPE->cpe_id == 0 ) ) + { + IF( NE_32( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) ) + { return error; -} -#endif -} + } + } -/*-----------------------------------------------------------------* - * DFT stereo mono DMX initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * DFT stereo mono DMX initialization + *-----------------------------------------------------------------*/ -IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) ) -{ - IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) + test(); + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); - } + IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) ); + } -#ifdef IVAS_FLOAT_FIXED - stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx ); -#else - stereo_dft_dmx_out_reset( hCPE->hStereoDftDmx ); -#endif -} + stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx ); + } -/*-----------------------------------------------------------------* - * Temporal inter-channel alignment initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Temporal inter-channel alignment initialization + *-----------------------------------------------------------------*/ -IF( ( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) ) && NE_16( hCPE->nchan_out, 1 ) ) -{ - IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + test(); + test(); + test(); + IF( ( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) ) && NE_16( hCPE->nchan_out, 1 ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); - } + IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) ); + } -#ifdef IVAS_FLOAT_FIXED - stereo_tca_init_dec_fx( hCPE->hStereoTCA ); -#else - stereo_tca_init_dec( hCPE->hStereoTCA ); -#endif -} + stereo_tca_init_dec_fx( hCPE->hStereoTCA ); + } -/*-----------------------------------------------------------------* - * Stereo IC BWE initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Stereo IC BWE initialization + *-----------------------------------------------------------------*/ -IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) ) -{ - IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + test(); + test(); + IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) ); - } + IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) ); + } -#ifdef IVAS_FLOAT_FIXED - stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); -#else - stereo_icBWE_init_dec( hCPE->hStereoICBWE ); -#endif -} + stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE ); + } -/*-----------------------------------------------------------------* - * TD stereo initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * TD stereo initialization + *-----------------------------------------------------------------*/ -IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) -{ - IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); - } + IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) ); + } - stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); -} + stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode ); + } -/*-----------------------------------------------------------------* - * MDCT stereo initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * MDCT stereo initialization + *-----------------------------------------------------------------*/ -IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) -{ - IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo MDCT\n" ) ); - } + IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo MDCT\n" ) ); + } - IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) - { - hCPE->hStereoMdct->use_itd = 1; - } - ELSE - { - hCPE->hStereoMdct->use_itd = 0; - } + test(); + IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) + { + hCPE->hStereoMdct->use_itd = 1; + move16(); + } + ELSE + { + hCPE->hStereoMdct->use_itd = 0; + move16(); + } - hCPE->hStereoMdct->reverse_dmx = 0; -#ifndef IVAS_FLOAT_FIXED - hCPE->hStereoMdct->smooth_ratio = 1.f; -#else - hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; -#endif - set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); - set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); -#ifndef IVAS_FLOAT_FIXED - hCPE->hStereoMdct->lastCoh = 1.f; -#else - hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14; -#endif - hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; - hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; - hCPE->hStereoMdct->IGFStereoMode[0] = -1; - hCPE->hStereoMdct->IGFStereoMode[1] = -1; -} + hCPE->hStereoMdct->reverse_dmx = 0; + move16(); + hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26; + move32(); + set_s( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB ); + set_s( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB ); + hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14; + move16(); + hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO; + move16(); + hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO; + move16(); + hCPE->hStereoMdct->IGFStereoMode[0] = -1; + move16(); + hCPE->hStereoMdct->IGFStereoMode[1] = -1; + move16(); + } -/*-----------------------------------------------------------------* - * Stereo CNG initialization - *-----------------------------------------------------------------*/ + /*-----------------------------------------------------------------* + * Stereo CNG initialization + *-----------------------------------------------------------------*/ -IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) -{ - IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) + test(); + IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) ); + IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) ); + } + stereo_cng_init_dec_fx( hCPE->hStereoCng, &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->frameSize ); } - stereo_cng_init_dec_fx( hCPE->hStereoCng, &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->frameSize ); -} -st_ivas->hCPE[cpe_id] = hCPE; + st_ivas->hCPE[cpe_id] = hCPE; -return error; + return error; } @@ -1302,7 +1441,7 @@ static void read_stereo_mode_and_bwidth_fx( { sts = hCPE->hCoreCoder; test(); - IF( st_ivas->hMCT && NE_16( hCPE->cpe_id, 0 ) ) + IF( st_ivas->hMCT && hCPE->cpe_id != 0 ) { sts[0]->bwidth = st_ivas->hCPE[0]->hCoreCoder[0]->bwidth; move16(); diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 1ce8d7f10..f81110cb5 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -55,7 +55,9 @@ ivas_error ivas_dec( { // TODO: move here function ivas_jbm_dec_tc() and rename it to ivas_dec() st_ivas->ivas_format = UNDEFINED_FORMAT; // temp. to avoid compilation warnings - data[0] = 0; // temp. to avoid compilation warnings + move32(); + data[0] = 0; // temp. to avoid compilation warnings + move16(); return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_decision_matrix_dec.c b/lib_dec/ivas_decision_matrix_dec.c index 4e19ae179..c6623f9e5 100644 --- a/lib_dec/ivas_decision_matrix_dec.c +++ b/lib_dec/ivas_decision_matrix_dec.c @@ -511,7 +511,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - IF( ( EQ_16( st->idchan, 0 ) && ( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) + IF( ( st->idchan == 0 && ( EQ_32( st->total_brate, FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) ) || ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LE_32( st->total_brate, SID_2k40 ) ) ) { st->core = ACELP_CORE; move16(); @@ -545,12 +545,13 @@ void ivas_decision_matrix_dec_fx( move16(); } } - ELSE IF( EQ_32( st->total_brate, SID_2k40 ) && EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->cng_sba_flag, 0 ) ) + ELSE IF( EQ_32( st->total_brate, SID_2k40 ) && EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && st->cng_sba_flag == 0 ) { /* read channel coherence */ Word16 index; index = get_next_indice( st, 4 ); st->hFdCngDec->hFdCngCom->coherence_fx = get_next_index_4_by_15[index]; + move16(); ///* TODO: remove floating point dependency */ // st->hFdCngDec->hFdCngCom->coherence_flt = ( (float) get_next_index_4_by_15[index] ) / ( ( 1 << 15 ) - 1 ); @@ -662,7 +663,7 @@ void ivas_decision_matrix_dec_fx( test(); test(); - IF( EQ_16( st->idchan, 1 ) && ( EQ_16( st->tdm_LRTD_flag, 0 ) || LT_16( st->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) ) + IF( EQ_16( st->idchan, 1 ) && ( st->tdm_LRTD_flag == 0 || LT_16( st->bits_frame_channel, IVAS_16k4 / FRAMES_PER_SEC ) ) ) { st->bwidth = WB; /* only WB in the secondary channel */ move16(); @@ -713,7 +714,7 @@ void ivas_decision_matrix_dec_fx( { st->extl = WB_BWE; move16(); - IF( GE_32( st->total_brate, MIN_BRATE_WB_BWE ) ) + if ( GE_32( st->total_brate, MIN_BRATE_WB_BWE ) ) { st->extl_brate = WB_BWE_0k35; move32(); @@ -721,7 +722,7 @@ void ivas_decision_matrix_dec_fx( } ELSE IF( EQ_16( st->bwidth, WB ) && ( LT_32( st->total_brate, MIN_BRATE_WB_BWE ) || ( EQ_16( st->idchan, 1 ) && EQ_16( st->element_mode, IVAS_CPE_TD ) ) ) ) { - IF( EQ_16( st->vbr_hw_BWE_disable_dec, 0 ) ) + if ( st->vbr_hw_BWE_disable_dec == 0 ) { st->extl = WB_BWE; move16(); @@ -757,6 +758,14 @@ void ivas_decision_matrix_dec_fx( } ELSE IF( EQ_16( st->bwidth, SWB ) || EQ_16( st->bwidth, FB ) ) { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( GE_32( st->total_brate, MIN_BRATE_SWB_BWE ) || ( GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) && st->tdm_LRTD_flag ) || ( LT_32( element_brate, IVAS_16k4 ) && GE_32( st->total_brate, MIN_MIN_BRATE_LRTD_SWB_BWE ) && EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->bwidth, SWB ) ) ) { /* read the SWB TBE/BWE selection bit */ @@ -775,6 +784,9 @@ void ivas_decision_matrix_dec_fx( move32(); st->extl_brate = SWB_TBE_1k6; move32(); + test(); + test(); + test(); IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) { st->extl_brate = SWB_TBE_2k8; @@ -824,6 +836,8 @@ void ivas_decision_matrix_dec_fx( move16(); st->extl_brate = FB_TBE_1k8; move32(); + test(); + test(); IF( GE_32( st->total_brate, MIN_BRATE_SWB_TBE_2k80 ) && st->flag_ACELP16k && EQ_16( st->element_mode, IVAS_SCE ) ) { st->extl_brate = FB_TBE_3k0; @@ -838,7 +852,7 @@ void ivas_decision_matrix_dec_fx( { icbwe_brate = STEREO_BITS_ICBWE * FRAMES_PER_SEC; move32(); - IF( EQ_16( st->flag_ACELP16k, 0 ) ) + if ( st->flag_ACELP16k == 0 ) { icbwe_brate = ( STEREO_BITS_ICBWE - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC; move32(); @@ -848,7 +862,7 @@ void ivas_decision_matrix_dec_fx( { icbwe_brate = STEREO_BITS_ICBWE_DFT * FRAMES_PER_SEC; move32(); - IF( EQ_16( st->flag_ACELP16k, 0 ) ) + if ( st->flag_ACELP16k == 0 ) { icbwe_brate = ( STEREO_BITS_ICBWE_DFT - STEREO_ICBWE_SPBITS ) * FRAMES_PER_SEC; move32(); @@ -860,7 +874,6 @@ void ivas_decision_matrix_dec_fx( test(); test(); test(); - test(); IF( GE_16( st->element_mode, IVAS_CPE_DFT ) && EQ_16( st->core, ACELP_CORE ) && ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && !( EQ_16( st->element_mode, IVAS_CPE_TD ) && st->tdm_LRTD_flag ) ) { icbwe_brate = L_add( icbwe_brate, STEREO_ICBWE_MSFLAG_BITS * FRAMES_PER_SEC ); @@ -994,7 +1007,7 @@ void ivas_decision_matrix_dec_fx( st->inactive_coder_type_flag = 0; /* AVQ by default */ move16(); - IF( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) + if ( LE_32( st->total_brate, MAX_GSC_INACTIVE_BRATE ) ) { st->inactive_coder_type_flag = 1; /* GSC */ move16(); @@ -1020,7 +1033,7 @@ void ivas_decision_matrix_dec_fx( move32(); } - IF( EQ_16( st->ini_frame, 0 ) ) + IF( st->ini_frame == 0 ) { /* avoid switching of internal ACELP Fs in the very first frame */ st->last_L_frame = st->L_frame; diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index afaa9d78a..a740ef159 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -65,16 +65,26 @@ static ivas_error ivas_dirac_dec_config_internal_fx( ivas_error error; DIRAC_CONFIG_FLAG flag_config; - flag_config = ( flag_config_inp == DIRAC_RECONFIGURE_MODE ) ? DIRAC_RECONFIGURE : flag_config_inp; + IF( EQ_32( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + flag_config = DIRAC_RECONFIGURE; + move32(); + } + ELSE + { + flag_config = flag_config_inp; + move32(); + } error = IVAS_ERR_OK; + move32(); hDirAC = NULL; - IF( flag_config == DIRAC_RECONFIGURE ) + IF( EQ_32( flag_config, DIRAC_RECONFIGURE ) ) { hDirAC = st_ivas->hDirAC; } - ELSE IF( flag_config == DIRAC_OPEN ) + ELSE IF( EQ_32( flag_config, DIRAC_OPEN ) ) { /*-----------------------------------------------------------------* * prepare library opening @@ -97,15 +107,26 @@ static ivas_error ivas_dirac_dec_config_internal_fx( * DirAC main configuration *-----------------------------------------------------------------*/ - IF( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_config( (void *) st_ivas, DEC ) ), IVAS_ERR_OK ) ) { return error; } - IF( flag_config == DIRAC_OPEN ) + IF( EQ_32( flag_config, DIRAC_OPEN ) ) { - hDirAC->spar_to_dirac_write_idx = ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) ? DELAY_DIRAC_PARAM_DEC_SFR : 0; + test(); + IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) + { + hDirAC->spar_to_dirac_write_idx = DELAY_DIRAC_PARAM_DEC_SFR; + move16(); + } + ELSE + { + hDirAC->spar_to_dirac_write_idx = 0; + move16(); + } hDirAC->dithering_seed = DIRAC_DITH_SEED; + move16(); st_ivas->hDirAC = hDirAC; } @@ -184,10 +205,10 @@ static ivas_error ivas_dirac_rend_config_fx( Word16 num_protos_diff_old; Word32 *proto_frame_f_old_fx; Word16 proto_signal_decorr_on_old; - uint16_t i, j, k; + UWord16 i, j, k; Word32 ls_azimuth_fx[MAX_OUTPUT_CHANNELS]; Word32 ls_elevation_fx[MAX_OUTPUT_CHANNELS]; - int32_t output_Fs, ivas_total_brate; + Word32 output_Fs, ivas_total_brate; ivas_error error; Word16 nchan_transport_orig; Word16 hodirac_flag; @@ -195,20 +216,32 @@ static ivas_error ivas_dirac_rend_config_fx( DIRAC_REND_HANDLE hDirACRend; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; -#ifdef IVAS_FLOAT_FIXED FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { ls_azimuth_fx[i] = 0; + move32(); ls_elevation_fx[i] = 0; + move32(); } -#endif - flag_config = ( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) ? DIRAC_RECONFIGURE : flag_config_inp; + IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + flag_config = DIRAC_RECONFIGURE; + move32(); + } + ELSE + { + flag_config = flag_config_inp; + move32(); + } error = IVAS_ERR_OK; + move32(); hDirACRend = NULL; output_Fs = st_ivas->hDecoderConfig->output_Fs; + move32(); ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; + move32(); hodirac_flag = ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ); hDirAC = st_ivas->hDirAC; @@ -230,24 +263,37 @@ static ivas_error ivas_dirac_rend_config_fx( } nchan_transport_old = 0; + move16(); } nchan_transport_old = 0; + move16(); num_outputs_dir_old = 0; + move16(); num_outputs_diff_old = 0; + move16(); num_protos_diff_old = 0; + move16(); nchan_transport_orig = st_ivas->nchan_transport; + move16(); + test(); IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { st_ivas->nchan_transport = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); } nchan_transport = st_ivas->nchan_transport; - IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) + move16(); + test(); + test(); + if ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) { nchan_transport = 1; + move16(); } + test(); + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { Word16 tmp1, tmp2, tmp3; @@ -260,7 +306,9 @@ static ivas_error ivas_dirac_rend_config_fx( hDirACRend->hOutSetup = st_ivas->hIntSetup; nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; + move16(); + test(); IF( hDirACRend->hOutSetup.ls_azimuth_fx != NULL && hDirACRend->hOutSetup.ls_elevation_fx != NULL ) { Copy32( hDirACRend->hOutSetup.ls_azimuth_fx, ls_azimuth_fx, nchan_out_woLFE ); @@ -270,25 +318,35 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( hDirACRend->hOutSetup.ambisonics_order, negate( (Word16) 1 ) ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_HOA3_ORDER; /* Order 3 is used by default in DirAC for SHD processing */ - IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) + move16(); + test(); + if ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_STEREO ) ) { hDirACRend->hOutSetup.ambisonics_order = SBA_FOA_ORDER; + move16(); } } - ELSE IF( GE_16( hDirACRend->hOutSetup.ambisonics_order, SBA_FOA_ORDER ) ) { Copy32( ls_azimuth_4d4_fx, ls_azimuth_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); Copy32( ls_elevation_4d4_fx, ls_elevation_fx, DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS ); } + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1_4 ) || ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hLsSetupCustom->separate_ch_found ) ) ) { /* Remove the channel of the separated signal from the output setup of the spatial synthesis */ hDirACRend->hOutSetup.nchan_out_woLFE = sub( hDirACRend->hOutSetup.nchan_out_woLFE, 1 ); nchan_out_woLFE = hDirACRend->hOutSetup.nchan_out_woLFE; - Copy32( &ls_azimuth_fx[add( hDirACRend->hOutSetup.separateChannelIndex, 1 )], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); - Copy32( &ls_elevation_fx[add( hDirACRend->hOutSetup.separateChannelIndex, 1 )], &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); + move16(); + Copy32( &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_azimuth_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); + Copy32( &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex + 1], &ls_elevation_fx[hDirACRend->hOutSetup.separateChannelIndex], sub( nchan_out_woLFE, hDirACRend->hOutSetup.separateChannelIndex ) ); } /*-----------------------------------------------------------------* @@ -296,32 +354,55 @@ static ivas_error ivas_dirac_rend_config_fx( *-----------------------------------------------------------------*/ st_ivas->nchan_transport = nchan_transport_orig; + move16(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( GT_16( nchan_transport_orig, 2 ) && hDirACRend->hOutSetup.is_loudspeaker_setup && EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && !hodirac_flag ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; + move32(); hDirACRend->panningConf = DIRAC_PANNING_VBAP; + move32(); } ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_MONO; + move32(); hDirACRend->panningConf = DIRAC_PANNING_HOA3; + move32(); nchan_out_woLFE = 1; + move16(); } ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && hDirACRend->hOutSetup.is_loudspeaker_setup ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_LS; + move32(); hDirACRend->panningConf = DIRAC_PANNING_VBAP; + move32(); } ELSE IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && !hDirACRend->hOutSetup.is_loudspeaker_setup && GT_32( st_ivas->nchan_transport, 1 ) ) { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_PSD_SHD; + move32(); hDirACRend->panningConf = DIRAC_PANNING_HOA3; + move32(); } ELSE { hDirACRend->synthesisConf = DIRAC_SYNTHESIS_GAIN_SHD; + move32(); hDirACRend->panningConf = DIRAC_PANNING_HOA3; + move32(); } IF( EQ_16( flag_config, DIRAC_OPEN ) ) @@ -334,8 +415,13 @@ static ivas_error ivas_dirac_rend_config_fx( ivas_dirac_dec_get_frequency_axis_fx( hDirACRend->frequency_axis_fx, output_Fs, hSpatParamRendCom->num_freq_bands ); } + test(); + test(); + test(); IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) ) && EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) && EQ_16( nchan_transport, 2 ) ) { + test(); + test(); IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect == NULL ) || EQ_16( flag_config, DIRAC_OPEN ) ) { IF( ( hDirACRend->masa_stereo_type_detect = (MASA_STEREO_TYPE_DETECT *) malloc( sizeof( MASA_STEREO_TYPE_DETECT ) ) ) == NULL ) @@ -347,6 +433,7 @@ static ivas_error ivas_dirac_rend_config_fx( } ELSE { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->masa_stereo_type_detect != NULL ) { free( hDirACRend->masa_stereo_type_detect ); @@ -355,6 +442,7 @@ static ivas_error ivas_dirac_rend_config_fx( } hSpatParamRendCom->numIsmDirections = 0; /* By default, no ism directions, set correct number runtime when needed */ + move16(); /*-----------------------------------------------------------------* * (re)configure sub-modules @@ -364,8 +452,11 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) { num_outputs_dir_old = hDirACRend->num_outputs_dir; + move16(); num_outputs_diff_old = hDirACRend->num_outputs_diff; + move16(); num_protos_diff_old = hDirACRend->num_protos_diff; + move16(); } /* allocate output setup related arrays */ @@ -373,7 +464,9 @@ static ivas_error ivas_dirac_rend_config_fx( { /* Directional and diffuses components in output LS format */ hDirACRend->num_outputs_diff = nchan_out_woLFE; + move16(); hDirACRend->num_outputs_dir = nchan_out_woLFE; + move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { @@ -385,12 +478,16 @@ static ivas_error ivas_dirac_rend_config_fx( ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { hDirACRend->num_outputs_diff = DIRAC_HOA_RENDERING_NUM_VIRT_DECORR_LS; + move16(); hDirACRend->num_outputs_dir = nchan_out_woLFE; + move16(); } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->num_outputs_diff = 1; /* There is one output channel in mono */ - hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ + move16(); + hDirACRend->num_outputs_dir = 2; /* Two channels are pre-rendered for stereo type detection */ + move16(); } ELSE { @@ -400,17 +497,20 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( flag_config, DIRAC_OPEN ) ) { num_outputs_dir_old = hDirACRend->num_outputs_dir; + move16(); IF( ( hDirACRend->proto_index_dir = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_dir ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } num_outputs_diff_old = hDirACRend->num_outputs_diff; + move16(); IF( ( hDirACRend->proto_index_diff = (Word16 *) malloc( sizeof( Word16 ) * hDirACRend->num_outputs_diff ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } + test(); IF( NE_16( hDirACRend->num_outputs_dir, num_outputs_dir_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) ) { free( hDirACRend->proto_index_dir ); @@ -421,6 +521,7 @@ static ivas_error ivas_dirac_rend_config_fx( } set16_fx( hDirACRend->proto_index_dir, 0, hDirACRend->num_outputs_dir ); + test(); IF( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) && EQ_16( flag_config, DIRAC_RECONFIGURE ) ) { free( hDirACRend->proto_index_diff ); @@ -433,9 +534,11 @@ static ivas_error ivas_dirac_rend_config_fx( hDirACRend->sba_map_tc = sba_map_tc; + test(); IF( ( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) ) || ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { - IF( GT_16( st_ivas->sba_order, SBA_FOA_ORDER ) && GE_32( ivas_total_brate, IVAS_512k ) ) + test(); + if ( GT_16( st_ivas->sba_order, SBA_FOA_ORDER ) && GE_32( ivas_total_brate, IVAS_512k ) ) { hDirACRend->sba_map_tc = sba_map_tc_512; } @@ -444,92 +547,121 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( nchan_transport, 1 ) ) { hDirACRend->num_protos_ambi = 1; + move16(); hDirACRend->num_protos_dir = 1; + move16(); hDirACRend->num_protos_diff = 1; + move16(); } ELSE IF( EQ_16( nchan_transport, 2 ) ) { IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { hDirACRend->num_protos_ambi = 2; + move16(); hDirACRend->num_protos_diff = 1; + move16(); hDirACRend->num_protos_dir = 2; + move16(); hDirACRend->proto_index_dir[1] = 1; + move16(); } ELSE IF( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_MONO ) ) { /* Following the foa rendering for code compatibility */ hDirACRend->num_protos_ambi = 2; + move16(); hDirACRend->num_protos_dir = 2; + move16(); hDirACRend->num_protos_diff = 3; + move16(); hDirACRend->proto_index_dir[0] = 0; + move16(); hDirACRend->proto_index_diff[0] = 0; + move16(); } ELSE { hDirACRend->num_protos_ambi = 2; + move16(); hDirACRend->num_protos_diff = 3; + move16(); FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) { - IF( GT_32( ls_azimuth_fx[k], 0 ) ) + IF( ls_azimuth_fx[k] > 0 ) { hDirACRend->proto_index_diff[k] = 1; + move16(); } - ELSE IF( LT_32( ls_azimuth_fx[k], 0 ) ) + ELSE IF( ls_azimuth_fx[k] < 0 ) { hDirACRend->proto_index_diff[k] = 2; + move16(); } ELSE { hDirACRend->proto_index_diff[k] = 0; + move16(); } } IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) { hDirACRend->num_protos_dir = 3; + move16(); Copy( hDirACRend->proto_index_diff, hDirACRend->proto_index_dir, nchan_out_woLFE ); } ELSE { hDirACRend->num_protos_dir = 2; + move16(); hDirACRend->proto_index_dir[1] = 1; + move16(); } } } ELSE /* nchan_transport > 2 */ { hDirACRend->num_protos_ambi = 4; + move16(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { hDirACRend->num_protos_diff = hDirACRend->num_outputs_diff; + move16(); FOR( k = 0; k < hDirACRend->num_outputs_diff; k++ ) { hDirACRend->proto_index_diff[k] = k; + move16(); } hDirACRend->num_protos_dir = hDirACRend->num_outputs_dir; + move16(); FOR( k = 0; k < hDirACRend->num_outputs_dir; k++ ) { hDirACRend->proto_index_dir[k] = k; + move16(); } } ELSE { hDirACRend->num_protos_diff = 1; + move16(); hDirACRend->num_protos_dir = nchan_transport; + move16(); FOR( k = 0; k < s_min( hDirACRend->num_outputs_dir, hDirACRend->num_protos_dir ); k++ ) { - IF( hDirACRend->sba_map_tc[k] < hDirACRend->num_outputs_dir ) + if ( LT_16( hDirACRend->sba_map_tc[k], hDirACRend->num_outputs_dir ) ) { hDirACRend->proto_index_dir[hDirACRend->sba_map_tc[k]] = k; + move16(); } } } } + test(); /* direct/diffuse responses */ IF( EQ_16( flag_config, DIRAC_OPEN ) ) { @@ -548,6 +680,9 @@ static ivas_error ivas_dirac_rend_config_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } } + + test(); + test(); IF( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) || ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) ) { initDiffuseResponses_fx( hDirACRend->diffuse_response_function_fx, nchan_out_woLFE, hDirACRend->hOutSetup.output_config, @@ -561,6 +696,8 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) { + test(); + test(); IF( EQ_16( flag_config, DIRAC_OPEN ) ) { IF( ( hDirACRend->hoa_encoder_fx = (Word32 *) malloc( nchan_out_woLFE * hDirACRend->num_outputs_diff * sizeof( Word32 ) ) ) == NULL ) @@ -582,6 +719,7 @@ static ivas_error ivas_dirac_rend_config_fx( } ELSE { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->hoa_encoder_fx ) { free( hDirACRend->hoa_encoder_fx ); @@ -590,24 +728,27 @@ static ivas_error ivas_dirac_rend_config_fx( } /* VBAP */ - IF( EQ_16( flag_config, DIRAC_OPEN ) ) + if ( EQ_16( flag_config, DIRAC_OPEN ) ) { st_ivas->hVBAPdata = NULL; } - IF( hDirACRend->panningConf == DIRAC_PANNING_VBAP ) + test(); + IF( EQ_32( hDirACRend->panningConf, DIRAC_PANNING_VBAP ) ) { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL ) { vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); } - IF( ( error = vbap_init_data_fx( &( st_ivas->hVBAPdata ), ls_azimuth_fx, ls_elevation_fx, nchan_out_woLFE, st_ivas->ivas_format ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = vbap_init_data_fx( &( st_ivas->hVBAPdata ), ls_azimuth_fx, ls_elevation_fx, nchan_out_woLFE, st_ivas->ivas_format ) ), IVAS_ERR_OK ) ) { return error; } } ELSE IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { + test(); IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && st_ivas->hVBAPdata != NULL ) { vbap_free_data_fx( &( st_ivas->hVBAPdata ) ); @@ -623,6 +764,8 @@ static ivas_error ivas_dirac_rend_config_fx( IF( EQ_16( flag_config, DIRAC_OPEN ) ) { hDirACRend->hoa_decoder = NULL; + test(); + test(); IF( ( EQ_16( hDirACRend->panningConf, DIRAC_PANNING_HOA3 ) ) || EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || ( GT_16( nchan_transport, 2 ) ) ) { IF( hDirACRend->hOutSetup.is_loudspeaker_setup ) @@ -632,7 +775,7 @@ static ivas_error ivas_dirac_rend_config_fx( free( st_ivas->hoa_dec_mtx ); st_ivas->hoa_dec_mtx = NULL; } - IF( ( error = ivas_sba_get_hoa_dec_matrix_fx( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_sba_get_hoa_dec_matrix_fx( hDirACRend->hOutSetup, &st_ivas->hoa_dec_mtx, hDirACRend->hOutSetup.ambisonics_order ) ), IVAS_ERR_OK ) ) { return error; } @@ -643,184 +786,237 @@ static ivas_error ivas_dirac_rend_config_fx( } /* decorrelation */ - proto_signal_decorr_on_old = ( flag_config == DIRAC_RECONFIGURE ) ? hDirACRend->proto_signal_decorr_on : 0; + IF( flag_config == DIRAC_RECONFIGURE ) + { + proto_signal_decorr_on_old = hDirACRend->proto_signal_decorr_on; + move16(); + } + ELSE + { + proto_signal_decorr_on_old = 0; + move16(); + } hDirACRend->proto_signal_decorr_on = 1; - IF( ( GT_16( nchan_transport, 2 ) ) && ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) ) ) + move16(); + test(); + if ( ( GT_16( nchan_transport, 2 ) ) && ( ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) ) ) { /*switch off decorrelation for 4 transport channels*/ hDirACRend->proto_signal_decorr_on = 0; + move16(); } - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { hDirACRend->proto_signal_decorr_on = 0; + move16(); } - IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ){ -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ){ - return error; -} -#else - IF( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ){ - return error; -} -#endif -} -ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) -{ - ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); -} -ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) -{ - IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirACRend->proto_signal_decorr_on ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirACRend->proto_signal_decorr_on && !proto_signal_decorr_on_old ) ) ) { - /* close and reopen the decorrelator */ - ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); -#ifdef IVAS_FLOAT_FIXED - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + Word16 nchan_transport_tmp; + IF( GT_16( nchan_transport, 2 ) ) { - return error; + nchan_transport_tmp = 4; + move16(); } -#else - IF( ( error = ivas_dirac_dec_decorr_open( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, - hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis, nchan_transport > 2 ? 4 : nchan_transport, output_Fs ) ) != IVAS_ERR_OK ) + ELSE + { + nchan_transport_tmp = nchan_transport; + move16(); + } + IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport_tmp, output_Fs ) ), + IVAS_ERR_OK ) ) { return error; } -#endif } -} - -/* output synthesis */ -IF( EQ_16( flag_config, DIRAC_OPEN ) ) -{ - IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( !hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) ) { - return error; + ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); } - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; -} -ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) ) -{ - ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); - - IF( ( ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ) != IVAS_ERR_OK ) + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_signal_decorr_on && proto_signal_decorr_on_old ) { - return error; + test(); + test(); + IF( NE_16( nchan_transport, nchan_transport_old ) || NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) || EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + Word16 nchan_transport_tmp; + IF( GT_16( nchan_transport, 2 ) ) + { + nchan_transport_tmp = 4; + move16(); + } + ELSE + { + nchan_transport_tmp = nchan_transport; + move16(); + } + /* close and reopen the decorrelator */ + ivas_dirac_dec_decorr_close_fx( &hDirACRend->h_freq_domain_decorr_ap_params, &hDirACRend->h_freq_domain_decorr_ap_state ); + IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( hDirACRend->h_freq_domain_decorr_ap_params ), &( hDirACRend->h_freq_domain_decorr_ap_state ), hSpatParamRendCom->num_freq_bands, hDirACRend->num_outputs_diff, + hDirACRend->num_protos_diff, hDirACRend->synthesisConf, hDirACRend->frequency_axis_fx, nchan_transport_tmp, output_Fs ) ), + IVAS_ERR_OK ) ) + { + return error; + } + } } - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; -} -IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) -{ - hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; -} + /* output synthesis */ + test(); + test(); + IF( EQ_16( flag_config, DIRAC_OPEN ) ) + { + IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ), IVAS_ERR_OK ) ) + { + return error; + } + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; + move16(); + } + ELSE IF( ( EQ_16( flag_config, DIRAC_RECONFIGURE ) ) && ( ( NE_16( nchan_transport, nchan_transport_old ) ) || ( NE_16( hDirACRend->num_outputs_diff, num_outputs_diff_old ) ) ) ) + { + ivas_dirac_dec_output_synthesis_close_fx( hDirACRend ); -/*-----------------------------------------------------------------* - * memory allocation - *-----------------------------------------------------------------*/ + IF( NE_32( ( error = ivas_dirac_dec_output_synthesis_open_fx( hSpatParamRendCom, hDirACRend, st_ivas->renderer_type, nchan_transport, output_Fs, hodirac_flag ) ), IVAS_ERR_OK ) ) + { + return error; + } + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = hDirACRend->proto_signal_decorr_on; + move16(); + } -IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) -{ - IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx ) + test(); + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) || EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - free( hDirACRend->proto_frame_f_fx ); + hDirACRend->h_output_synthesis_psd_params.use_onset_filters = 0; + move16(); } - hDirACRend->proto_frame_f_fx = NULL; -} -ELSE -{ - IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) ) + + /*-----------------------------------------------------------------* + * memory allocation + *-----------------------------------------------------------------*/ + + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + test(); + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + free( hDirACRend->proto_frame_f_fx ); } + hDirACRend->proto_frame_f_fx = NULL; } - ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) ) + ELSE { - proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx; - free( proto_frame_f_old_fx ); - IF( ( hDirACRend->proto_frame_f_fx = (Word32 *) malloc( sizeof( Word32 ) * 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands ) ) == NULL ) + test(); + test(); + test(); + IF( EQ_16( flag_config, DIRAC_OPEN ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->proto_frame_f_fx == NULL ) ) { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + 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" ) ); + } } + ELSE IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( NE_16( hDirACRend->num_protos_diff, num_protos_diff_old ) ) ) + { + proto_frame_f_old_fx = hDirACRend->proto_frame_f_fx; + free( proto_frame_f_old_fx ); + 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 = imult1616( 2, imult1616( hDirACRend->num_protos_diff, hSpatParamRendCom->num_freq_bands ) ); } - hDirACRend->proto_frame_f_len = 2 * hDirACRend->num_protos_diff * hSpatParamRendCom->num_freq_bands; -} -IF( EQ_16( flag_config, DIRAC_OPEN ) ) -{ - hDirACRend->buffer_energy_fx = NULL; -} + if ( EQ_16( flag_config, DIRAC_OPEN ) ) + { + hDirACRend->buffer_energy_fx = NULL; + } -IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == TRUE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) -{ - hDirACRend->index_buffer_intensity = 0; - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == TRUE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == TRUE && dec_param_estim_old == FALSE ) ) ) { - FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + hDirACRend->index_buffer_intensity = 0; + move16(); + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) { - IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + IF( ( hDirACRend->buffer_intensity_real_fx[i][j] = (Word32 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); + } + set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + } + set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF ); + IF( hDirACRend->buffer_energy_fx == NULL ) + { + IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); } - set32_fx( hDirACRend->buffer_intensity_real_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX ); + } + set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); + set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF ); + } + ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) + { + FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + { + FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) + { + IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) + { + free( hDirACRend->buffer_intensity_real_fx[i][j] ); + } + hDirACRend->buffer_intensity_real_fx[i][j] = NULL; + } + } + IF( hDirACRend->buffer_energy_fx != NULL ) + { + free( hDirACRend->buffer_energy_fx ); + hDirACRend->buffer_energy_fx = NULL; } } - set16_fx( hDirACRend->q_buffer_intensity_real, Q31, DIRAC_NO_COL_AVG_DIFF ); - IF( hDirACRend->buffer_energy_fx == NULL ) + /* output synthesis */ + ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); + + /* Allocate stack memory */ + IF( NE_16( flag_config, DIRAC_OPEN ) ) { - IF( ( hDirACRend->buffer_energy_fx = (Word32 *) malloc( DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX * sizeof( Word32 ) ) ) == NULL ) - { - return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC\n" ) ); - } + ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); } - set32_fx( hDirACRend->buffer_energy_fx, 0, DIRAC_NO_COL_AVG_DIFF * CLDFB_NO_CHANNELS_MAX ); - set16_fx( hDirACRend->q_buffer_energy, Q31, DIRAC_NO_COL_AVG_DIFF ); -} -ELSE IF( ( EQ_16( flag_config, DIRAC_OPEN ) && hDirAC->hConfig->dec_param_estim == FALSE ) || ( EQ_16( flag_config, DIRAC_RECONFIGURE ) && ( hDirAC->hConfig->dec_param_estim == FALSE && dec_param_estim_old == TRUE ) ) ) -{ - FOR( i = 0; i < DIRAC_NUM_DIMS; i++ ) + IF( NE_32( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ), IVAS_ERR_OK ) ) { - FOR( j = 0; j < DIRAC_NO_COL_AVG_DIFF; j++ ) - { - IF( EQ_16( flag_config, DIRAC_RECONFIGURE ) && hDirACRend->buffer_intensity_real_fx[i][j] ) - { - free( hDirACRend->buffer_intensity_real_fx[i][j] ); - } - hDirACRend->buffer_intensity_real_fx[i][j] = NULL; - } + return error; } - IF( hDirACRend->buffer_energy_fx != NULL ) + + if ( EQ_16( flag_config, DIRAC_OPEN ) ) { - free( hDirACRend->buffer_energy_fx ); - hDirACRend->buffer_energy_fx = NULL; + st_ivas->hDirACRend = hDirACRend; } -} -/* output synthesis */ -ivas_dirac_dec_output_synthesis_init_fx( hSpatParamRendCom, hDirACRend, nchan_out_woLFE, hodirac_flag ); -/* Allocate stack memory */ -IF( NE_16( flag_config, DIRAC_OPEN ) ) -{ - ivas_dirac_free_mem_fx( &( hDirACRend->stack_mem ) ); -} -IF( ( error = ivas_dirac_alloc_mem( hDirACRend, st_ivas->renderer_type, hSpatParamRendCom->num_freq_bands, &( hDirACRend->stack_mem ), hodirac_flag ) ) != IVAS_ERR_OK ) -{ return error; } - -IF( EQ_16( flag_config, DIRAC_OPEN ) ) -{ - st_ivas->hDirACRend = hDirACRend; -} - -return error; -} #else static ivas_error ivas_dirac_rend_config( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -1477,24 +1673,45 @@ ivas_error ivas_dirac_dec_config_fx( Word16 dec_param_estim_new; error = IVAS_ERR_OK; + move32(); /* Solve and setup flags for inits */ - dec_config_flag = ( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) ? DIRAC_RECONFIGURE : flag_config_inp; + IF( EQ_16( flag_config_inp, DIRAC_RECONFIGURE_MODE ) ) + { + dec_config_flag = DIRAC_RECONFIGURE; + move32(); + } + ELSE + { + dec_config_flag = flag_config_inp; + move32(); + } output_Fs = st_ivas->hDecoderConfig->output_Fs; move32(); hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); - dec_param_estim_old = ( dec_config_flag == DIRAC_RECONFIGURE ) ? st_ivas->hDirAC->hConfig->dec_param_estim : FALSE; + IF( EQ_32( dec_config_flag, DIRAC_RECONFIGURE ) ) + { + dec_param_estim_old = st_ivas->hDirAC->hConfig->dec_param_estim; + move16(); + } + ELSE + { + dec_param_estim_old = FALSE; + move16(); + } sparfoa_flag = 0; move16(); + test(); + test(); IF( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_FOA && st_ivas->ivas_format == SBA_FORMAT && !hodirac_flag ) { sparfoa_flag = 1; move16(); } - IF( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_config_internal_fx( st_ivas, dec_config_flag ) ), IVAS_ERR_OK ) ) { return error; } @@ -1502,7 +1719,7 @@ ivas_error ivas_dirac_dec_config_fx( /* This is required for parambin */ test(); test(); - IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) + if ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { st_ivas->hDirAC->hConfig->dec_param_estim = FALSE; move16(); @@ -1559,16 +1776,35 @@ ivas_error ivas_dirac_dec_config_fx( IF( !sparfoa_flag ) { - common_rend_config_flag = st_ivas->hSpatParamRendCom == NULL ? DIRAC_OPEN : flag_config_inp; - IF( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, - st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ) != IVAS_ERR_OK ) + IF( st_ivas->hSpatParamRendCom == NULL ) + { + common_rend_config_flag = DIRAC_OPEN; + move32(); + } + ELSE + { + common_rend_config_flag = flag_config_inp; + move32(); + } + IF( NE_32( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, dec_param_estim_new, + st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, hodirac_flag, 0 ) ), + IVAS_ERR_OK ) ) { return error; } IF( need_dirac_rend ) { - rend_config_flag = st_ivas->hDirACRend == NULL ? DIRAC_OPEN : flag_config_inp; - IF( ( error = ivas_dirac_rend_config_fx( st_ivas, rend_config_flag, dec_param_estim_old ) ) != IVAS_ERR_OK ) + IF( st_ivas->hDirACRend == NULL ) + { + rend_config_flag = DIRAC_OPEN; + move32(); + } + ELSE + { + rend_config_flag = flag_config_inp; + move32(); + } + IF( NE_32( ( error = ivas_dirac_rend_config_fx( st_ivas, rend_config_flag, dec_param_estim_old ) ), IVAS_ERR_OK ) ) { return error; } @@ -1579,7 +1815,7 @@ ivas_error ivas_dirac_dec_config_fx( IF( NE_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) { /*WIP*/ - IF( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_binaural_copy_hrtfs( &st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } @@ -1587,7 +1823,7 @@ ivas_error ivas_dirac_dec_config_fx( IF( st_ivas->hDiracDecBin == NULL ) { - IF( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_init_binaural_data_fx( st_ivas, st_ivas->hHrtfParambin ) ), IVAS_ERR_OK ) ) { return error; } @@ -1595,12 +1831,14 @@ ivas_error ivas_dirac_dec_config_fx( ELSE { /* This is required to keep BE in rate switching. This probably means that 1TC and 2TC MASA perform differently. */ + test(); + test(); IF( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params != NULL && !( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nSCE > 0 ) ) { ivas_dirac_dec_decorr_close_fx( &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params, &st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ); // done } - IF( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin->hTdDecorr ), &( st_ivas->hDiracDecBin->useTdDecorr ) ) ), IVAS_ERR_OK ) ) { return error; } @@ -1613,8 +1851,9 @@ ivas_error ivas_dirac_dec_config_fx( Word16 frequency_axis_fx[CLDFB_NO_CHANNELS_MAX]; ivas_dirac_dec_get_frequency_axis_fx( frequency_axis_fx, st_ivas->hDecoderConfig->output_Fs, st_ivas->hSpatParamRendCom->num_freq_bands ); - IF( ( error = ivas_dirac_dec_decorr_open_fx( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, - DIRAC_SYNTHESIS_PSD_LS, frequency_axis_fx, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + IF( NE_32( ( error = ivas_dirac_dec_decorr_open_fx( &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_params ), &( st_ivas->hDiracDecBin->h_freq_domain_decorr_ap_state ), st_ivas->hSpatParamRendCom->num_freq_bands, BINAURAL_CHANNELS, BINAURAL_CHANNELS, + DIRAC_SYNTHESIS_PSD_LS, frequency_axis_fx, BINAURAL_CHANNELS, st_ivas->hDecoderConfig->output_Fs ) ), + IVAS_ERR_OK ) ) { return error; } @@ -1825,6 +2064,7 @@ void ivas_dirac_dec_close_fx( { DIRAC_DEC_HANDLE hDirAC; + test(); IF( hDirAC_out == NULL || *hDirAC_out == NULL ) { return; @@ -1865,6 +2105,7 @@ void ivas_dirac_dec_read_BS_fx( { Word16 i, j, b, dir, orig_dirac_bands; Word16 next_bit_pos_orig; + Word32 quo, rem; test(); test(); @@ -1872,8 +2113,9 @@ void ivas_dirac_dec_read_BS_fx( { next_bit_pos_orig = st->next_bit_pos; move16(); - st->next_bit_pos = extract_l( L_sub( ivas_total_brate / FRAMES_PER_SEC, 1 ) ); - IF( GT_16( last_bit_pos, 0 ) ) + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + st->next_bit_pos = extract_l( L_sub( quo, 1 ) ); + if ( last_bit_pos > 0 ) { st->next_bit_pos = last_bit_pos; move16(); @@ -1892,7 +2134,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); /* if we start with a SID frame, we need to init the azi/ele arrays.*/ - IF( EQ_16( st->ini_frame, 0 ) ) + IF( st->ini_frame == 0 ) { FOR( b = 0; b < hQMetaData->q_direction[0].cfg.nbands; b++ ) { @@ -1901,6 +2143,7 @@ void ivas_dirac_dec_read_BS_fx( } } *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ) ); + move16(); FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { @@ -1936,6 +2179,7 @@ void ivas_dirac_dec_read_BS_fx( hQMetaData->sba_inactive_mode = 0; move16(); hQMetaData->is_masa_ivas_format = 0; + move16(); IF( hQMetaData->useLowerRes ) { hQMetaData->q_direction[0].cfg.nblocks = 1; @@ -1947,6 +2191,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); } *nb_bits = add( *nb_bits, ivas_qmetadata_dec_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), hodirac_flag ) ); + move16(); } st->next_bit_pos = next_bit_pos_orig; @@ -1958,7 +2203,8 @@ void ivas_dirac_dec_read_BS_fx( move16(); /* subtract mode signaling bits, since bitstream was moved after mode reading */ - st->next_bit_pos = extract_l( L_sub( L_sub( ivas_total_brate / FRAMES_PER_SEC, 1 ), SID_FORMAT_NBITS ) ); + iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 ); + st->next_bit_pos = extract_l( L_sub( L_sub( quo, 1 ), SID_FORMAT_NBITS ) ); move16(); /* 1 bit flag for signaling metadata to read */ b = st->bit_stream[( st->next_bit_pos )--]; @@ -1970,7 +2216,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); /* if we start with a SID frame, we need to init the azi/ele arrays.*/ - IF( EQ_16( st->ini_frame, 0 ) ) + IF( st->ini_frame == 0 ) { FOR( dir = 0; dir < hQMetaData->no_directions; dir++ ) { @@ -1982,6 +2228,7 @@ void ivas_dirac_dec_read_BS_fx( } } *nb_bits = add( *nb_bits, ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT ) ); + move16(); FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth_fx[i] = hQMetaData->q_direction[0].band_data[1].azimuth_fx[0]; @@ -2015,6 +2262,7 @@ void ivas_dirac_dec_read_BS_fx( move16(); } + test(); IF( hDirAC != NULL && hSpatParamRendCom != NULL ) { ivas_qmetadata_to_dirac_fx( hQMetaData, hDirAC, NULL, hSpatParamRendCom, ivas_total_brate, SBA_FORMAT, hodirac_flag, dirac_to_spar_md_bands ); @@ -2197,6 +2445,7 @@ void ivas_qmetadata_to_dirac_fx( q_direction = &( hQMetaData->q_direction[0] ); hSpatParamRendCom->numParametricDirections = hQMetaData->no_directions; + move16(); hSpatParamRendCom->numSimultaneousDirections = add( hSpatParamRendCom->numParametricDirections, hSpatParamRendCom->numIsmDirections ); test(); @@ -2272,7 +2521,7 @@ void ivas_qmetadata_to_dirac_fx( move32(); /* Sanitize diffuseness for rare cases where floating point inaccuracy could result in negative diffuseness. */ - IF( LT_32( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b], 0 ) ) + if ( hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] < 0 ) { hSpatParamRendCom->diffuseness_vector_fx[meta_write_index][b] = 0; move32(); @@ -2353,7 +2602,7 @@ void ivas_qmetadata_to_dirac_fx( nbands = hDirAC->hConfig->nbands; move16(); - IF( EQ_16( hQMetaData->q_direction[0].cfg.nblocks, 0 ) ) + if ( hQMetaData->q_direction[0].cfg.nblocks == 0 ) { /* No transmission -> no copy from qmetadata buffers*/ nbands = start_band; @@ -2402,7 +2651,7 @@ void ivas_qmetadata_to_dirac_fx( } /* Bands with spatial data transmitted */ - IF( hodirac_flag ) + if ( hodirac_flag ) { no_secs = DIRAC_HO_NUMSECTORS; move16(); @@ -2433,7 +2682,6 @@ void ivas_qmetadata_to_dirac_fx( move16(); diffuseness_fx = L_sub( ONE_IN_Q30, q_direction->band_data[qBand_idx].energy_ratio_fx[0] ); - move32(); FOR( block = 0; block < MAX_PARAM_SPATIAL_SUBFRAMES; block++ ) { @@ -2443,7 +2691,7 @@ void ivas_qmetadata_to_dirac_fx( block_qmetadata = s_max( block_qmetadata, 0 ); - IF( LT_32( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata], 0 ) ) + if ( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] < 0 ) { q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata] = L_add( q_direction[idx_sec].band_data[qBand_idx].azimuth_fx[block_qmetadata], 1509949440 /*360.0F in Q22*/ ); move32(); @@ -2478,11 +2726,11 @@ void ivas_qmetadata_to_dirac_fx( azi = extract_h( L_shr( ( L_add( azimuth_fx, ONE_IN_Q21 ) ), 6 ) ); ele = extract_h( L_shr( ( L_add( elevation_fx, ONE_IN_Q21 ) ), 6 ) ); /*addition of one to compensate precision loss*/ - IF( LT_16( azi, 0 ) ) + if ( azi < 0 ) { azi = add( azi, 1 ); } - IF( LT_16( ele, 0 ) ) + if ( ele < 0 ) { ele = add( ele, 1 ); } @@ -2517,11 +2765,11 @@ void ivas_qmetadata_to_dirac_fx( ele = extract_h( L_shr( final_2_32, 31 - final_2_exp - 16 ) ); /*addition of one to compensate precision loss*/ - IF( LT_16( azi, 0 ) ) + if ( azi < 0 ) { azi = add( azi, 1 ); } - IF( LT_16( ele, 0 ) ) + if ( ele < 0 ) { ele = add( ele, 1 ); } @@ -2562,7 +2810,7 @@ void ivas_qmetadata_to_dirac_fx( IF( hodirac_flag ) { - IF( EQ_16( idx_sec, 0 ) ) + IF( idx_sec == 0 ) { hSpatParamRendCom->elevation[tmp_write_idx_band][b] = ele; move16(); @@ -2594,8 +2842,8 @@ void ivas_qmetadata_to_dirac_fx( move16(); } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) @@ -2936,8 +3184,8 @@ void ivas_qmetadata_to_dirac( tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ for ( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) @@ -2989,17 +3237,25 @@ void ivas_dirac_dec_set_md_map( /* adapt subframes */ hSpatParamRendCom->num_slots = nCldfbTs; + move16(); hSpatParamRendCom->slots_rendered = 0; + move16(); num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); hSpatParamRendCom->subframes_rendered = 0; + move16(); ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes ); /* copy also to tc buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ + test(); + test(); + test(); IF( ( st_ivas->ivas_format != MASA_ISM_FORMAT || st_ivas->ism_mode != ISM_MASA_MODE_DISC ) && !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) { st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes; + move16(); mvs2s( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes ); } @@ -3007,7 +3263,9 @@ void ivas_dirac_dec_set_md_map( set_s( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - IF( st_ivas->ivas_format == MASA_FORMAT ) + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } @@ -3020,24 +3278,30 @@ void ivas_dirac_dec_set_md_map( ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } + test(); + test(); IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { Word64 tmp_fx; Word16 sf_idx, slot_idx, slot_idx_abs; + Word32 quo, rem; slot_idx_abs = 0; + move16(); FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ ) { tmp_fx = 0; + move64(); FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ ) { - tmp_fx += hSpatParamRendCom->render_to_md_map[slot_idx_abs]; - slot_idx_abs++; + tmp_fx = W_add_nosat( tmp_fx, W_deposit32_l( L_deposit_l( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) ) ); + slot_idx_abs = add( slot_idx_abs, 1 ); } - hSpatParamRendCom->render_to_md_map[sf_idx] = ( round_fx( (Word32) ( tmp_fx << 16 ) / hSpatParamRendCom->subframe_nbslots[sf_idx] ) + hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; + iDiv_and_mod_32( W_extract_l( W_shl_nosat( tmp_fx, 16 ) ), hSpatParamRendCom->subframe_nbslots[sf_idx], &quo, &rem, 0 ); + hSpatParamRendCom->render_to_md_map[sf_idx] = add( round_fx( quo ), hSpatParamRendCom->dirac_read_idx ) % hSpatParamRendCom->dirac_md_buffer_length; } - set_s( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hSpatParamRendCom->nb_subframes ); + set_s( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); } return; @@ -3127,17 +3391,25 @@ void ivas_dirac_dec_set_md_map_fx( /* adapt subframes */ hSpatParamRendCom->num_slots = nCldfbTs; + move16(); hSpatParamRendCom->slots_rendered = 0; + move16(); num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES; + move16(); hSpatParamRendCom->subframes_rendered = 0; + move16(); ivas_jbm_dec_get_adapted_subframes( nCldfbTs, hSpatParamRendCom->subframe_nbslots, &hSpatParamRendCom->nb_subframes ); /* copy also to tc buffer */ /* only for non-combined formats and combinded formats w/o discrete objects */ + test(); + test(); + test(); IF( ( st_ivas->ivas_format != MASA_ISM_FORMAT || st_ivas->ism_mode != ISM_MASA_MODE_DISC ) && !( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) ) { st_ivas->hTcBuffer->nb_subframes = hSpatParamRendCom->nb_subframes; + move16(); Copy( hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, hSpatParamRendCom->nb_subframes ); } @@ -3145,7 +3417,9 @@ void ivas_dirac_dec_set_md_map_fx( set16_fx( hSpatParamRendCom->render_to_md_map, 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME ); - IF( st_ivas->ivas_format == MASA_FORMAT ) + test(); + test(); + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) { ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } @@ -3158,6 +3432,8 @@ void ivas_dirac_dec_set_md_map_fx( ivas_jbm_dec_get_md_map( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbTs, num_slots_in_subfr, hSpatParamRendCom->dirac_read_idx, hSpatParamRendCom->dirac_md_buffer_length, hSpatParamRendCom->render_to_md_map ); } + test(); + test(); IF( hDirAC == NULL || hDirAC->hConfig == NULL || hDirAC->hConfig->dec_param_estim == 0 ) { Word16 sf_idx, slot_idx, slot_idx_abs; @@ -3168,9 +3444,11 @@ void ivas_dirac_dec_set_md_map_fx( Word16 ans_fix_16, exp_final; slot_idx_abs = 0; + move16(); FOR( sf_idx = 0; sf_idx < hSpatParamRendCom->nb_subframes; sf_idx++ ) { tmp_fx = 0; + move32(); FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[sf_idx]; slot_idx++ ) { tmp_fx = L_add( tmp_fx, L_deposit_h( hSpatParamRendCom->render_to_md_map[slot_idx_abs] ) ); @@ -3178,17 +3456,22 @@ void ivas_dirac_dec_set_md_map_fx( } exp_denom = 15, exp_num = 31; + move16(); + move16(); norm_num = norm_l( tmp_fx ); num = L_shl( tmp_fx, norm_num ); - exp_num = exp_num - norm_num; + exp_num = sub( exp_num, norm_num ); + move16(); norm_denom = norm_s( hSpatParamRendCom->subframe_nbslots[sf_idx] ); denom = shl( hSpatParamRendCom->subframe_nbslots[sf_idx], norm_denom ); - exp_denom = exp_denom - norm_denom; + exp_denom = sub( exp_denom, norm_denom ); + move16(); exp = sub( exp_num, exp_denom ); + move16(); - IF( num > denom ) + IF( GT_32( num, L_deposit_l( denom ) ) ) { num = L_shr( num, 1 ); exp = add( exp, 1 ); @@ -3196,11 +3479,12 @@ void ivas_dirac_dec_set_md_map_fx( ans = div_l( num, denom ); ans_fix_32 = BASOP_Util_Add_Mant32Exp( ans, exp, L_deposit_h( hSpatParamRendCom->dirac_read_idx ), 15 /*31 - 16*/, &exp_final ); - ans_fix_16 = round_fx( L_shr( ans_fix_32, 31 - exp_final - 16 ) ); + ans_fix_16 = round_fx( L_shr( ans_fix_32, sub( sub( Q31, exp_final ), Q16 ) ) ); hSpatParamRendCom->render_to_md_map[sf_idx] = ans_fix_16 % hSpatParamRendCom->dirac_md_buffer_length; + move16(); } - set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME - hSpatParamRendCom->nb_subframes ); + set16_fx( &hSpatParamRendCom->render_to_md_map[hSpatParamRendCom->nb_subframes], 0, sub( MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME, hSpatParamRendCom->nb_subframes ) ); } return; @@ -3225,6 +3509,7 @@ void ivas_dirac_dec_render_fx( Word16 slots_to_render, first_sf, last_sf, subframe_idx; UWord16 slot_size, n_samples_sf, ch, nchan_intern; Word16 temp = 0; + move16(); SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; Word32 *output_f_local_fx[MAX_OUTPUT_CHANNELS]; Word32 output_f_local_buff_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k] = { 0 }; // VE2SB: TBV @@ -3251,10 +3536,11 @@ void ivas_dirac_dec_render_fx( last_sf = first_sf; move16(); - WHILE( GT_16( slots_to_render, 0 ) ) + WHILE( slots_to_render > 0 ) { slots_to_render = sub( slots_to_render, hSpatParamRendCom->subframe_nbslots[last_sf] ); - last_sf++; + last_sf = add( last_sf, 1 ); + move16(); } FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) @@ -3278,6 +3564,8 @@ void ivas_dirac_dec_render_fx( FOR( ch = 0; ch < nchan_intern; ch++ ) { + test(); + test(); IF( !( L_and( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ), ( L_or( EQ_16( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, ch ), EQ_16( add( st_ivas->hDirACRend->hOutSetup.separateChannelIndex, 1 ), ch ) ) ) ) ) ) { Copy32( output_f_local_buff_fx[ch], output_fx[ch], *nSamplesRendered ); @@ -3412,6 +3700,8 @@ void ivas_dirac_dec_render_sf_fx( Word32 Cldfb_RealBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_Binaural_fx[BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX]; Word16 index = 0, num_freq_bands = 0; + move16(); + move16(); /* local copies of azi, ele, diffuseness */ Word16 azimuth[CLDFB_NO_CHANNELS_MAX]; @@ -3423,12 +3713,16 @@ void ivas_dirac_dec_render_sf_fx( Word32 surCohEner_fx; Word32 surCohRatio_fx[CLDFB_NO_CHANNELS_MAX]; Word16 surCohRatio_q_fx = 0, temp_q = 0; + move16(); + move16(); Word32 Cldfb_RealBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word32 Cldfb_ImagBuffer_Temp_fx[2][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX]; Word16 cldfb_buf_q; Word16 offset, buff_len; Word16 q_cldfb, q_temp_cldfb = 0; + move16(); Word16 proto_length = 0; + move16(); Word16 q_proto_direct_buffer[CLDFB_SLOTS_PER_SUBFRAME]; Word16 q_proto_diffuse_buffer[CLDFB_SLOTS_PER_SUBFRAME]; Word16 size, size_ho; @@ -3438,11 +3732,15 @@ void ivas_dirac_dec_render_sf_fx( uint16_t coherence_flag; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; Word16 scale = 0; + move16(); DIRAC_OUTPUT_SYNTHESIS_PARAMS *h_dirac_output_synthesis_params; DIRAC_OUTPUT_SYNTHESIS_STATE *h_dirac_output_synthesis_state; Word16 num_channels_dir, exp; Word16 q_diffuseness_vector = Q31, q_reference_power_smooth = Q31; + move16(); + move16(); Word16 proto_power_smooth_len = 0; + move16(); Word16 tmp1; push_wmops( "ivas_dirac_dec_render" ); @@ -3455,80 +3753,117 @@ void ivas_dirac_dec_render_sf_fx( DirAC_mem = hDirACRend->stack_mem; reference_power_fx = DirAC_mem.reference_power_fx; - reference_power_smooth_fx = ( DirAC_mem.reference_power_fx == NULL ) ? NULL : DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; + IF( DirAC_mem.reference_power_fx == NULL ) + { + reference_power_smooth_fx = NULL; + } + ELSE + { + reference_power_smooth_fx = DirAC_mem.reference_power_fx + hSpatParamRendCom->num_freq_bands; + } onset_filter_fx = DirAC_mem.onset_filter_fx; - onset_filter_subframe_fx = ( DirAC_mem.onset_filter_fx == NULL ) ? NULL : DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + IF( DirAC_mem.onset_filter_fx == NULL ) + { + onset_filter_subframe_fx = NULL; + } + ELSE + { + onset_filter_subframe_fx = DirAC_mem.onset_filter_fx + hSpatParamRendCom->num_freq_bands; + } q_cldfb = Q11; move16(); set_s( q_proto_direct_buffer, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); set_s( q_proto_diffuse_buffer, hDirACRend->h_output_synthesis_psd_state.proto_diffuse_buffer_f_q, CLDFB_SLOTS_PER_SUBFRAME ); set_zero_fx( surCohRatio_fx, CLDFB_NO_CHANNELS_MAX ); - //////////////////////////////////////////////////////////////////////////// to be removed /////////////////////////////////////////////////////////////////// + IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_MONO ) ) { IF( hDirACRend->masa_stereo_type_detect ) { hDirACRend->masa_stereo_type_detect->subtract_power_y_fx = 0; + move32(); hDirACRend->masa_stereo_type_detect->q_subtract_power_y = Q31; + move16(); } } + test(); IF( L_or( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ), EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { - if ( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 ) + IF( hDirACRend->h_output_synthesis_psd_params.max_band_decorr != 0 ) { DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state ); tmp1 = L_norm_arr( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len ); scale_sig32( state->proto_power_diff_smooth_fx, state->proto_power_diff_smooth_len, tmp1 ); - state->proto_power_diff_smooth_q += tmp1; + state->proto_power_diff_smooth_q = add( state->proto_power_diff_smooth_q, tmp1 ); } } h_dirac_output_synthesis_params = &( hDirACRend->h_output_synthesis_psd_params ); h_dirac_output_synthesis_state = &( hDirACRend->h_output_synthesis_psd_state ); num_channels_dir = hDirACRend->num_outputs_dir; + move16(); hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); - if ( hDirACRend->synthesisConf == DIRAC_SYNTHESIS_PSD_LS ) + if ( EQ_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; + move16(); } - if ( h_dirac_output_synthesis_params->use_onset_filters && ( hDirAC->hConfig->dec_param_estim != TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) ) + test(); + test(); + IF( h_dirac_output_synthesis_params->use_onset_filters && ( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { - tmp1 = getScaleFactor32( 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, num_channels_dir * hSpatParamRendCom->num_freq_bands, tmp1 - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ); + tmp1 = getScaleFactor32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), sub( tmp1, h_dirac_output_synthesis_state->q_cy_auto_diff_smooth ) ); h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = tmp1; + move16(); } - if ( hDirAC->hConfig->dec_param_estim == TRUE && hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) + test(); + IF( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ) && NE_32( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - Word16 shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, shift ); - h_dirac_output_synthesis_state->q_cy_auto_dir_smooth += shift; + Word16 shift; + shift = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + h_dirac_output_synthesis_state->q_cy_auto_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_dir_smooth, shift ); - shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands ); - scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, num_channels_dir * hSpatParamRendCom->num_freq_bands, shift ); - h_dirac_output_synthesis_state->q_cy_cross_dir_smooth += shift; + shift = L_norm_arr( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_cross_dir_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), shift ); + h_dirac_output_synthesis_state->q_cy_cross_dir_smooth = add( h_dirac_output_synthesis_state->q_cy_cross_dir_smooth, shift ); - tmp1 = 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, num_channels_dir * hSpatParamRendCom->num_freq_bands, tmp1 ); - h_dirac_output_synthesis_state->q_cy_auto_diff_smooth += tmp1; + tmp1 = L_norm_arr( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( h_dirac_output_synthesis_state->cy_auto_diff_smooth_fx, imult1616( num_channels_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, tmp1 ); } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11; + move16(); } } - else if ( !L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) + ELSE IF( !L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { + Word16 outchannels; idx_lfe = 0; + move16(); idx_in = 0; - Word16 outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + move16(); + outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || @@ -3539,11 +3874,13 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add( outchannels, 1 ); } + test(); IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) ) { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -3556,12 +3893,16 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { - Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); + Word16 cldfbSynIdx; + cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11; + move16(); } } ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled ) && EQ_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) @@ -3570,66 +3911,82 @@ void ivas_dirac_dec_render_sf_fx( ELSE { st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11; + move16(); idx_in = add( idx_in, 1 ); } } } } - /////////////////////////////////////////////////////////////////////////////////////////////// - size = hDirACRend->num_outputs_dir * hSpatParamRendCom->num_freq_bands; - size_ho = ( hodirac_flag ) ? size * DIRAC_HO_NUMSECTORS : size; - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ); + size = imult1616( hDirACRend->num_outputs_dir, hSpatParamRendCom->num_freq_bands ); + IF( hodirac_flag ) + { + size_ho = imult1616( size, DIRAC_HO_NUMSECTORS ); + } + ELSE + { + size_ho = size; + move16(); + } + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_fx, size, sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q ) ); hDirACRend->h_output_synthesis_psd_state.gains_dir_prev_q = Q26; + move16(); IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); + Word16 shift; + shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_fx, size_ho, 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 ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, sub( Q26, 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(); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, 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_auto_diff_smooth_prev_fx, hDirACRend->num_outputs_diff * hDirACRend->h_output_synthesis_psd_params.max_band_decorr, Q26 - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hDirACRend->num_outputs_diff, hDirACRend->h_output_synthesis_psd_params.max_band_decorr ), sub( Q26, 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(); } ELSE { - scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE, Q26 - hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ); + Word16 shift; + scale_sig32( hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), sub( Q26, hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q ) ); hDirACRend->h_output_synthesis_psd_state.gains_diff_prev_q = Q26; + move16(); - Word16 shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); + shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_dir_smooth_prev_fx, size_ho, 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 ); shift = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho ); scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_cross_dir_smooth_prev_fx, size_ho, 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 ); - tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, hSpatParamRendCom->num_freq_bands * hDirACRend->hOutSetup.nchan_out_woLFE, tmp1 ); - hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev += tmp1; + tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.cy_auto_diff_smooth_prev_fx, imult1616( hSpatParamRendCom->num_freq_bands, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + 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, tmp1 ); - tmp1 = 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->num_protos_dir * hSpatParamRendCom->num_freq_bands, tmp1 ); - hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q += tmp1; + tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_fx, imult1616( hDirACRend->num_protos_dir, hSpatParamRendCom->num_freq_bands ), tmp1 ); + hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q = add( hDirACRend->h_output_synthesis_psd_state.proto_power_smooth_prev_q, tmp1 ); IF( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx != 0 ) { - tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_params.max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE ); - scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, hDirACRend->h_output_synthesis_psd_params.max_band_decorr * hDirACRend->hOutSetup.nchan_out_woLFE, tmp1 ); - hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_q += tmp1; + tmp1 = L_norm_arr( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); + scale_sig32( hDirACRend->h_output_synthesis_psd_state.proto_power_diff_smooth_prev_fx, imult1616( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ), tmp1 ); + 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, tmp1 ); } } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// hodirac_flag = ivas_get_hodirac_flag_fx( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ); - IF( st_ivas->hQMetaData != NULL && st_ivas->ivas_format != SBA_FORMAT && st_ivas->ivas_format != SBA_ISM_FORMAT ) + test(); + test(); + IF( st_ivas->hQMetaData != NULL && NE_32( st_ivas->ivas_format, SBA_FORMAT ) && NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { coherence_flag = st_ivas->hQMetaData->coherence_flag; move16(); @@ -3683,11 +4040,12 @@ void ivas_dirac_dec_render_sf_fx( set_zero_fx( onset_filter_subframe_fx, hSpatParamRendCom->num_freq_bands ); } + test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] ) { p_Rmat_fx = &st_ivas->hCombinedOrientationData->Rmat_fx[st_ivas->hCombinedOrientationData->subframe_idx][0][0]; - IF( EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + IF( st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) { num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; move16(); @@ -3704,6 +4062,7 @@ void ivas_dirac_dec_render_sf_fx( IF( EQ_16( hDirAC->hConfig->dec_param_estim, FALSE ) ) { + Word16 *masa_band_mapping; /* compute response */ IF( hDirACRend->synthesisConf != DIRAC_SYNTHESIS_GAIN_SHD ) { @@ -3746,7 +4105,11 @@ void ivas_dirac_dec_render_sf_fx( } ELSE { - Word16 max_exp_direct = 0, max_exp_diffusion = 0; + Word16 max_exp_direct, max_exp_diffusion; + max_exp_direct = 0; + move16(); + max_exp_diffusion = 0; + move16(); ivas_dirac_dec_compute_gain_factors_fx( hSpatParamRendCom->num_freq_bands, hSpatParamRendCom->diffuseness_vector_fx[md_idx], hDirACRend->h_output_synthesis_psd_state.direct_power_factor_fx, @@ -3760,8 +4123,7 @@ void ivas_dirac_dec_render_sf_fx( { FOR( i = 0; i < hSpatParamRendCom->num_freq_bands; i++ ) { - surCohRatio_fx[i] = (Word32) hSpatParamRendCom->surroundingCoherence_fx[md_idx][i]; - move32(); + surCohRatio_fx[i] = L_deposit_l( hSpatParamRendCom->surroundingCoherence_fx[md_idx][i] ); } } ELSE @@ -3772,12 +4134,22 @@ void ivas_dirac_dec_render_sf_fx( move16(); } + IF( st_ivas->hMasa == NULL ) + { + masa_band_mapping = NULL; + } + ELSE + { + masa_band_mapping = st_ivas->hMasa->data.band_mapping; + } + test(); + test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 1 ) ) { ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, hDirACRend, st_ivas->hVBAPdata, - st_ivas->hMasa == NULL ? NULL : st_ivas->hMasa->data.band_mapping, + masa_band_mapping, st_ivas->hMasaIsmData, azimuth, elevation, @@ -3793,7 +4165,7 @@ void ivas_dirac_dec_render_sf_fx( ivas_dirac_dec_compute_directional_responses_fx( hSpatParamRendCom, hDirACRend, st_ivas->hVBAPdata, - st_ivas->hMasa == NULL ? NULL : st_ivas->hMasa->data.band_mapping, + masa_band_mapping, st_ivas->hMasaIsmData, azimuth, elevation, @@ -3806,6 +4178,7 @@ void ivas_dirac_dec_render_sf_fx( } } + test(); IF( L_and( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ), EQ_16( nchan_transport, 2 ) ) ) { FOR( slot_idx = 0; slot_idx < hSpatParamRendCom->subframe_nbslots[subframe_idx]; slot_idx++ ) @@ -3827,6 +4200,7 @@ void ivas_dirac_dec_render_sf_fx( move16(); } + test(); IF( L_and( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ), NE_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) ) { ivas_omasa_preProcessStereoTransportsForMovedObjects_fx( st_ivas, Cldfb_RealBuffer_Temp_fx, Cldfb_ImagBuffer_Temp_fx, &cldfb_buf_q, hSpatParamRendCom->num_freq_bands, subframe_idx ); @@ -3846,6 +4220,8 @@ void ivas_dirac_dec_render_sf_fx( md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; move16(); } + test(); + test(); IF( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) { FOR( ch = 0; ch < nchan_transport; ch++ ) @@ -3883,12 +4259,17 @@ void ivas_dirac_dec_render_sf_fx( } /* CNG in DirAC, extra CLDFB ana for CNA*/ + test(); + test(); + test(); + test(); IF( EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag && !( L_or( EQ_16( st_ivas->ivas_format, SBA_FORMAT ), EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ) ) { Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0]; Word16 Q_input = Q11; move16(); q_temp_cldfb = Q11; + move16(); generate_masking_noise_dirac_ivas_fx( st->hFdCngDec->hFdCngCom, st_ivas->cldfbAnaDec[1], st_ivas->hTcBuffer->tc_fx[1], @@ -3902,7 +4283,10 @@ void ivas_dirac_dec_render_sf_fx( } /* LFE synthesis */ - IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && EQ_16( hDirACRend->hOutSetup.num_lfe, 0 ) ) ) + test(); + test(); + test(); + IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled && !( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && hDirACRend->hOutSetup.num_lfe == 0 ) ) { ivas_lfe_synth_with_cldfb_fx( st_ivas->hMasa->hMasaLfeSynth, Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, @@ -3917,7 +4301,9 @@ void ivas_dirac_dec_render_sf_fx( *-----------------------------------------------------------------*/ IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { - IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + test(); + test(); + IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) { protoSignalComputation_shd_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, hDirACRend->h_output_synthesis_psd_state.proto_direct_buffer_f_fx, @@ -4048,7 +4434,10 @@ void ivas_dirac_dec_render_sf_fx( { Copy( &hSpatParamRendCom->azimuth[md_idx][hDirAC->hConfig->enc_param_start_band], &azimuth[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) ); Copy( &hSpatParamRendCom->elevation[md_idx][hDirAC->hConfig->enc_param_start_band], &elevation[hDirAC->hConfig->enc_param_start_band], sub( hSpatParamRendCom->num_freq_bands, hDirAC->hConfig->enc_param_start_band ) ); - IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && EQ_16( st_ivas->hCombinedOrientationData->shd_rot_max_order, 0 ) ) + + test(); + test(); + IF( ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) && st_ivas->hCombinedOrientationData->shd_rot_max_order == 0 ) { num_freq_bands = hDirAC->band_grouping[hDirAC->hConfig->enc_param_start_band]; move16(); @@ -4056,9 +4445,10 @@ void ivas_dirac_dec_render_sf_fx( } /*hDirACRend->index_buffer_intensity = ( hDirACRend->index_buffer_intensity % DIRAC_NO_COL_AVG_DIFF ) + 1 */ - IF( EQ_16( hDirACRend->index_buffer_intensity, 0 ) ) + IF( hDirACRend->index_buffer_intensity == 0 ) { hDirACRend->index_buffer_intensity = 1; + move16(); } ELSE { @@ -4072,19 +4462,19 @@ void ivas_dirac_dec_render_sf_fx( computeIntensityVector_dec_fx( Cldfb_RealBuffer_fx, Cldfb_ImagBuffer_fx, q_cldfb, num_freq_bands, - hDirACRend->buffer_intensity_real_fx[0][sub( index, 1 )], - hDirACRend->buffer_intensity_real_fx[1][sub( index, 1 )], - hDirACRend->buffer_intensity_real_fx[2][sub( index, 1 )], - &hDirACRend->q_buffer_intensity_real[sub( index, 1 )] ); - - computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][sub( index, 1 )], - hDirACRend->buffer_intensity_real_fx[1][sub( index, 1 )], - hDirACRend->buffer_intensity_real_fx[2][sub( index, 1 )], - hDirACRend->q_buffer_intensity_real[sub( index, 1 )], + hDirACRend->buffer_intensity_real_fx[0][index - 1], + hDirACRend->buffer_intensity_real_fx[1][index - 1], + hDirACRend->buffer_intensity_real_fx[2][index - 1], + &hDirACRend->q_buffer_intensity_real[index - 1] ); + + computeDirectionAngles_fx( hDirACRend->buffer_intensity_real_fx[0][index - 1], + hDirACRend->buffer_intensity_real_fx[1][index - 1], + hDirACRend->buffer_intensity_real_fx[2][index - 1], + hDirACRend->q_buffer_intensity_real[index - 1], num_freq_bands, azimuth, elevation ); Copy32( reference_power_fx, &( hDirACRend->buffer_energy_fx[i_mult( sub( index, 1 ), num_freq_bands )] ), num_freq_bands ); - hDirACRend->q_buffer_energy[sub( index, 1 )] = DirAC_mem.reference_power_q; + hDirACRend->q_buffer_energy[index - 1] = DirAC_mem.reference_power_q; move16(); computeDiffuseness_fixed( hDirACRend->buffer_intensity_real_fx, hDirACRend->buffer_energy_fx, num_freq_bands, hSpatParamRendCom->diffuseness_vector_fx[md_idx], hDirACRend->q_buffer_intensity_real, hDirACRend->q_buffer_energy, &hSpatParamRendCom->q_diffuseness_vector ); @@ -4103,11 +4493,11 @@ void ivas_dirac_dec_render_sf_fx( hDirACRend->num_protos_diff, hDirACRend->synthesisConf, nchan_transport, - &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_fx[imult1616( imult1616( imult1616( 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[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_fx[add( imult1616( imult1616( imult1616( slot_idx, 2 ), hSpatParamRendCom->num_freq_bands ), hDirACRend->num_outputs_diff ), imult1616( imult1616( 2, hSpatParamRendCom->num_freq_bands ), s_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, @@ -4168,10 +4558,13 @@ void ivas_dirac_dec_render_sf_fx( /*-----------------------------------------------------------------* * output synthesis *-----------------------------------------------------------------*/ + test(); IF( L_or( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ), EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_SHD ) ) ) { - DIRAC_OUTPUT_SYNTHESIS_STATE *state = &( hDirACRend->h_output_synthesis_psd_state ); - Word16 diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); + DIRAC_OUTPUT_SYNTHESIS_STATE *state; + Word16 diffuse_start; + state = &( hDirACRend->h_output_synthesis_psd_state ); + diffuse_start = i_mult( i_mult( slot_idx, 2 ), i_mult( hDirACRend->h_output_synthesis_psd_params.max_band_decorr, hDirACRend->hOutSetup.nchan_out_woLFE ) ); exp = getScaleFactor32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len ); scale_sig32( hDirACRend->proto_frame_dec_f_fx, hDirACRend->proto_frame_dec_f_len, exp ); @@ -4191,12 +4584,14 @@ void ivas_dirac_dec_render_sf_fx( num_channels_dir = hDirACRend->num_outputs_dir; move16(); - IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) + if ( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_PSD_LS ) ) { num_channels_dir = hDirACRend->hOutSetup.nchan_out_woLFE; move16(); } + test(); + test(); IF( L_and( h_dirac_output_synthesis_params->use_onset_filters, L_and( NE_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) ) { Scale_sig32( h_dirac_output_synthesis_state->diffuse_power_factor_fx, h_dirac_output_synthesis_params->max_band_decorr, sub( Q31, h_dirac_output_synthesis_state->diffuse_power_factor_q ) ); @@ -4208,6 +4603,7 @@ void ivas_dirac_dec_render_sf_fx( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); } + test(); IF( L_and( EQ_16( hDirAC->hConfig->dec_param_estim, TRUE ), NE_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) ) { scale_sig32( h_dirac_output_synthesis_state->direct_power_factor_fx, hSpatParamRendCom->num_freq_bands, sub( Q31, h_dirac_output_synthesis_state->direct_power_factor_q ) ); @@ -4239,6 +4635,8 @@ void ivas_dirac_dec_render_sf_fx( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth = add( h_dirac_output_synthesis_state->q_cy_auto_diff_smooth, exp ); } + test(); + test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[st_ivas->hCombinedOrientationData->subframe_idx] && st_ivas->hCombinedOrientationData->shd_rot_max_order > 0 ) { ivas_dirac_dec_output_synthesis_process_slot_fx( reference_power_fx, @@ -4282,9 +4680,10 @@ void ivas_dirac_dec_render_sf_fx( IF( hDirAC->hConfig->dec_param_estim ) { - Word16 fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp ); + Word16 fac; Flag flag = 0; move32(); + fac = BASOP_Util_Divide3232_Scale( 1, hSpatParamRendCom->subframe_nbslots[subframe_idx], &exp ); fac = shl_o( fac, exp, &flag ); IF( LT_16( q_diffuseness_vector, hSpatParamRendCom->q_diffuseness_vector ) ) @@ -4449,6 +4848,7 @@ void ivas_dirac_dec_render_sf_fx( &hDirACRend->h_output_synthesis_psd_state.q_cy_cross_dir_smooth_prev, &hDirACRend->h_output_synthesis_psd_state.q_cy_auto_diff_smooth_prev ); + test(); IF( hDirACRend->hOutSetup.is_loudspeaker_setup && hDirACRend->hoa_decoder != NULL ) { FOR( ch = 0; ch < hDirACRend->hOutSetup.nchan_out_woLFE; ch++ ) @@ -4618,9 +5018,13 @@ void ivas_dirac_dec_render_sf_fx( index_slot = slot_idx_start_cldfb_synth; move16(); + test(); + test(); IF( L_or( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { /* render objects in combined format onto the CICP19 channels for BINAURAL_ROOM_IR */ + test(); + test(); IF( L_and( L_and( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ), EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) ), EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) ) { Word16 in_ch; @@ -4645,6 +5049,7 @@ void ivas_dirac_dec_render_sf_fx( interp_offset = st_ivas->hTcBuffer->n_samples_rendered; move16(); + test(); IF( st_ivas->hCombinedOrientationData && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] ) { ivas_jbm_dec_get_adapted_linear_interpolator_fx( n_samples_to_render, n_samples_to_render, st_ivas->hIsmRendererData->interpolator_fx ); @@ -4654,6 +5059,7 @@ void ivas_dirac_dec_render_sf_fx( FOR( i = 0; i < num_objects; i++ ) { /* Combined rotation: rotate the object positions depending the head and external orientations */ + test(); IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) ) { Word16 az_q0 = extract_l( L_shr( st_ivas->hIsmMetaData[i]->azimuth_fx, Q22 ) ); @@ -4675,23 +5081,25 @@ void ivas_dirac_dec_render_sf_fx( move16(); for ( j = 0, j2 = 0; j < nchan_out_woLFE; j++, j2++ ) { - IF( L_and( GT_16( st_ivas->hIntSetup.num_lfe, 0 ), ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) + test(); + IF( L_and( st_ivas->hIntSetup.num_lfe > 0, ( EQ_16( st_ivas->hIntSetup.index_lfe[lfe_index], j ) ) ) ) { IF( LT_16( lfe_index, sub( st_ivas->hIntSetup.num_lfe, 1 ) ) ) { - lfe_index++; - j2++; + lfe_index = add( lfe_index, 1 ); + j2 = add( j2, 1 ); } ELSE { - j2++; + j2 = add( j2, 1 ); } } gain_fx = st_ivas->hIsmRendererData->gains_fx[i][j]; move32(); prev_gain_fx = st_ivas->hIsmRendererData->prev_gains_fx[i][j]; move32(); - IF( L_or( GT_32( L_abs( gain_fx ), 0 ), GT_32( L_abs( prev_gain_fx ), 0 ) ) ) + test(); + IF( L_or( L_abs( gain_fx ) > 0, L_abs( prev_gain_fx ) > 0 ) ) { Word32 *tc_re_fx, *tc_im_fx; Word16 *w1_fx, w2_fx; @@ -4719,7 +5127,8 @@ void ivas_dirac_dec_render_sf_fx( } } /* update here only in case of head rotation */ - IF( st_ivas->hCombinedOrientationData != NULL && st_ivas->hCombinedOrientationData->enableCombinedOrientation[0] == 1 ) + test(); + IF( st_ivas->hCombinedOrientationData != NULL && EQ_16( st_ivas->hCombinedOrientationData->enableCombinedOrientation[0], 1 ) ) { st_ivas->hIsmRendererData->prev_gains_fx[i][j] = gain_fx; move32(); @@ -4730,7 +5139,8 @@ void ivas_dirac_dec_render_sf_fx( } /* Perform binaural rendering */ - Word16 input_q = Q6; + Word16 input_q; + input_q = Q6; move16(); ivas_binRenderer_fx( st_ivas->hBinRenderer, @@ -4802,6 +5212,13 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || @@ -4812,6 +5229,7 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add( outchannels, 1 ); } + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { Word32 tmp_separated_fx[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; @@ -4824,7 +5242,9 @@ void ivas_dirac_dec_render_sf_fx( Copy32( &( output_buf_fx[LFE_CHANNEL][subframe_start_sample] ), tmp_lfe_fx, num_samples_subframe ); FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { /* Move the LFE channel to the correct place */ Copy32( tmp_lfe_fx, &( output_buf_fx[ch][subframe_start_sample] ), num_samples_subframe ); @@ -4867,8 +5287,12 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { + test(); + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { FOR( i = 0; i < hSpatParamRendCom->subframe_nbslots[subframe_idx]; i++ ) @@ -4963,31 +5387,44 @@ void ivas_dirac_dec_render_sf_fx( hSpatParamRendCom->subframes_rendered = add( hSpatParamRendCom->subframes_rendered, 1 ); -#ifdef IVAS_FLOAT_FIXED - /////////////////////////////////////////////////////// FIXED TO FLOAT ////////////////////////////////////////////////////////////////////////////////////////// IF( EQ_16( hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) { 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(); } - if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) { - for ( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) + FOR( i = 0; i < st_ivas->hDecoderConfig->nchan_out; i++ ) { scale_sig32( st_ivas->cldfbSynDec[i]->cldfb_state_fx, st_ivas->cldfbSynDec[i]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[i]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[i]->Q_cldfb_state = Q11; + move16(); } } - else if ( st_ivas->ivas_format == SBA_FORMAT || st_ivas->ivas_format == SBA_ISM_FORMAT ) + ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { } - else + ELSE { + Word16 outchannels; idx_lfe = 0; + move16(); idx_in = 0; - Word16 outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + move16(); + outchannels = add( hDirACRend->hOutSetup.nchan_out_woLFE, hDirACRend->hOutSetup.num_lfe ); + test(); + test(); + test(); + test(); + test(); + test(); + test(); IF( hDirACRend->hOutSetup.separateChannelEnabled && ( EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_7_1 ) || EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || @@ -4998,11 +5435,13 @@ void ivas_dirac_dec_render_sf_fx( outchannels = add( outchannels, 1 ); } + test(); IF( ( hDirACRend->hOutSetup.separateChannelEnabled && EQ_16( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) ) { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { IF( LT_16( idx_lfe, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) { @@ -5015,28 +5454,36 @@ void ivas_dirac_dec_render_sf_fx( { FOR( ch = 0; ch < outchannels; ch++ ) { - IF( L_and( GT_16( hDirACRend->hOutSetup.num_lfe, 0 ), ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) + test(); + test(); + IF( L_and( hDirACRend->hOutSetup.num_lfe > 0, ( EQ_16( hDirACRend->hOutSetup.index_lfe[idx_lfe], ch ) ) ) ) { + test(); IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) && !hDirACRend->hOutSetup.separateChannelEnabled ) { Word16 cldfbSynIdx = add( hDirACRend->hOutSetup.nchan_out_woLFE, idx_lfe ); scale_sig32( st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_state_fx, st_ivas->cldfbSynDec[cldfbSynIdx]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[cldfbSynIdx]->Q_cldfb_state = Q11; + move16(); } } ELSE IF( ( hDirACRend->hOutSetup.separateChannelEnabled == 0 ) || NE_16( hDirACRend->hOutSetup.separateChannelIndex, ch ) ) { scale_sig32( st_ivas->cldfbSynDec[idx_in]->cldfb_state_fx, st_ivas->cldfbSynDec[idx_in]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state ) ); st_ivas->cldfbSynDec[idx_in]->Q_cldfb_state = Q11; + move16(); idx_in = add( idx_in, 1 ); } } } - if ( !hDirACRend->hOutSetup.separateChannelEnabled || hDirACRend->hOutSetup.output_config != IVAS_AUDIO_CONFIG_LS_CUSTOM ) + test(); + IF( !hDirACRend->hOutSetup.separateChannelEnabled || NE_32( hDirACRend->hOutSetup.output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) ) { Word16 tmp_lfe_idx = 0; - for ( ch = 0; ch < outchannels; ch++ ) + move16(); + FOR( ch = 0; ch < outchannels; ch++ ) { + test(); IF( ( hDirACRend->hOutSetup.num_lfe > 0 ) && ( EQ_16( hDirACRend->hOutSetup.index_lfe[tmp_lfe_idx], ch ) ) ) { IF( LT_16( tmp_lfe_idx, sub( hDirACRend->hOutSetup.num_lfe, 1 ) ) ) @@ -5047,8 +5494,6 @@ void ivas_dirac_dec_render_sf_fx( } } } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#endif pop_wmops(); diff --git a/lib_dec/ivas_dirac_output_synthesis_cov.c b/lib_dec/ivas_dirac_output_synthesis_cov.c index 11535dded..c11dda7cc 100644 --- a/lib_dec/ivas_dirac_output_synthesis_cov.c +++ b/lib_dec/ivas_dirac_output_synthesis_cov.c @@ -87,42 +87,40 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( /* buffer length and interpolator */ h_dirac_output_synthesis_params->alpha_synthesis_fx = NULL; - if ( ( h_dirac_output_synthesis_params->proto_matrix_fx = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_params->proto_matrix_fx = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - h_dirac_output_synthesis_params->proto_matrix_len = nchan_out * nchan_in; - move16(); + h_dirac_output_synthesis_params->proto_matrix_len = imult1616( nchan_out, nchan_in ); + /* cov buffers */ - for ( idx = 0; idx < num_param_bands; idx++ ) + FOR( idx = 0; idx < num_param_bands; idx++ ) { - - if ( ( h_dirac_output_synthesis_state->cx_old_fx[idx] = (Word32 *) malloc( nchan_in * nchan_in * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->cx_old_fx[idx] = (Word32 *) malloc( nchan_in * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - h_dirac_output_synthesis_state->cx_old_len = nchan_in * nchan_in; - move16(); - if ( ( h_dirac_output_synthesis_state->cy_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) + h_dirac_output_synthesis_state->cx_old_len = imult1616( nchan_in, nchan_in ); + IF( ( h_dirac_output_synthesis_state->cy_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - if ( ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], nchan_in * nchan_in ); - set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], nchan_out * nchan_out ); - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], nchan_out * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], imult1616( nchan_in, nchan_in ) ); + set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], imult1616( nchan_out, nchan_out ) ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], imult1616( nchan_out, nchan_in ) ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = (Word32 *) malloc( nchan_out * nchan_in * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], nchan_out * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], imult1616( nchan_out, nchan_in ) ); h_dirac_output_synthesis_state->mixing_matrix_len = i_mult( nchan_out, nchan_in ); } - for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { h_dirac_output_synthesis_state->cx_old_fx[idx] = NULL; h_dirac_output_synthesis_state->cy_old_fx[idx] = NULL; @@ -130,32 +128,32 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx] = NULL; } - for ( idx = 0; idx < num_param_bands_residual; idx++ ) + FOR( idx = 0; idx < num_param_bands_residual; idx++ ) { - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx], nchan_out * nchan_out ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = (Word32 *) malloc( nchan_out * nchan_out * sizeof( Word32 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], nchan_out * nchan_out ); h_dirac_output_synthesis_state->mixing_matrix_res_len = i_mult( nchan_out, nchan_out ); } - for ( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) + FOR( ; idx < CLDFB_NO_CHANNELS_MAX; idx++ ) { h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx] = NULL; h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx] = NULL; } - if ( ( h_dirac_output_synthesis_state->cx_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->cx_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } - if ( ( h_dirac_output_synthesis_state->cy_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->cy_old_e = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis covariance\n" ) ); } @@ -163,25 +161,25 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( set16_fx( h_dirac_output_synthesis_state->cx_old_e, 0, CLDFB_NO_CHANNELS_MAX ); set16_fx( h_dirac_output_synthesis_state->cy_old_e, 0, CLDFB_NO_CHANNELS_MAX ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_res_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } set16_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } set16_fx( h_dirac_output_synthesis_state->mixing_matrix_exp, 0, CLDFB_NO_CHANNELS_MAX ); - if ( ( h_dirac_output_synthesis_state->mixing_matrix_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) + IF( ( h_dirac_output_synthesis_state->mixing_matrix_old_exp = (Word16 *) malloc( CLDFB_NO_CHANNELS_MAX * sizeof( Word16 ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DirAC synthesis matrix\n" ) ); } @@ -202,6 +200,7 @@ ivas_error ivas_dirac_dec_output_synthesis_cov_open_fx( } Copy32( proto_matrix, h_dirac_output_synthesis_params->proto_matrix_fx, nchan_in * nchan_out ); h_dirac_output_synthesis_params->proto_matrix_e = 5; + move16(); return IVAS_ERR_OK; } #else @@ -339,8 +338,8 @@ void ivas_dirac_dec_output_synthesis_get_interpolator_fx( FOR( idx = 1; idx <= interp_length; ++idx ) { - tmp = BASOP_Util_Divide3232_Scale( (Word32) idx, (Word32) interp_length, &exp_diff ); // (Q15 - exp_diff) - h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = shl_sat( tmp, exp_diff ); // Q15 + tmp = BASOP_Util_Divide3232_Scale( L_deposit_l( idx ), L_deposit_l( interp_length ), &exp_diff ); // (Q15 - exp_diff) + h_dirac_output_synthesis_params->interpolator_fx[idx - 1] = shl_sat( tmp, exp_diff ); // Q15 move16(); } @@ -390,16 +389,16 @@ void ivas_dirac_dec_output_synthesis_cov_init_fx( /* initialize buffers */ FOR( idx = 0; idx < n_param_bands; idx++ ) { - set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], nchan_in * nchan_in ); - set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], nchan_out * nchan_out ); - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], nchan_out * nchan_in ); - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], nchan_out * nchan_in ); + set_zero_fx( h_dirac_output_synthesis_state->cx_old_fx[idx], imult1616( nchan_in, nchan_in ) ); + set_zero_fx( h_dirac_output_synthesis_state->cy_old_fx[idx], imult1616( nchan_out, nchan_out ) ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_old_fx[idx], imult1616( nchan_out, nchan_in ) ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_fx[idx], imult1616( nchan_out, nchan_in ) ); } FOR( idx = 0; idx < n_param_bands_res; idx++ ) { - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx], nchan_out * nchan_out ); - set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], nchan_out * nchan_out ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_old_fx[idx], imult1616( nchan_out, nchan_out ) ); + set_zero_fx( h_dirac_output_synthesis_state->mixing_matrix_res_fx[idx], imult1616( nchan_out, nchan_out ) ); } @@ -778,18 +777,16 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( move16(); brange[1] = hParamMC->band_grouping[param_band + 1]; move16(); - num_bands = brange[1] - brange[0]; - move16(); + num_bands = sub( brange[1], brange[0] ); FOR( band_idx = 0; band_idx < num_bands; band_idx++ ) { - band = brange[0] + band_idx; - move16(); + band = add( brange[0], band_idx ); FOR( ch_idx = 0; ch_idx < nchan_in; ch_idx++ ) { - real_in_buffer_fx[band_idx + num_bands * ch_idx] = RealBuffer_fx[ch_idx * hParamMC->num_freq_bands + band]; + real_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = RealBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; move32(); - imag_in_buffer_fx[band_idx + num_bands * ch_idx] = ImagBuffer_fx[ch_idx * hParamMC->num_freq_bands + band]; + imag_in_buffer_fx[add( band_idx, imult1616( num_bands, ch_idx ) )] = ImagBuffer_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; move32(); } } @@ -809,17 +806,17 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( i = 0; i < num_bands * nchan_in; ++i ) { - real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], output_e - RealBuffer_e ); + real_in_buffer_fx[i] = L_shr( real_in_buffer_fx[i], sub( output_e, RealBuffer_e ) ); move32(); - imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], output_e - ImagBuffer_e ); + imag_in_buffer_fx[i] = L_shr( imag_in_buffer_fx[i], sub( output_e, ImagBuffer_e ) ); move32(); } cmplx_matrix_square_fx( real_in_buffer_fx, imag_in_buffer_fx, num_bands, nchan_in, real_buffer_fx, imag_buffer_fx, output_e, &output_e ); - v_add_fixed_me( cx_fx[param_band], *cx_e, real_buffer_fx, output_e, cx_fx[param_band], &tmp1_e, nchan_in * nchan_in, 1 ); + v_add_fixed_me( cx_fx[param_band], *cx_e, real_buffer_fx, output_e, cx_fx[param_band], &tmp1_e, imult1616( nchan_in, nchan_in ), 1 ); - v_add_fixed_me( cx_imag_fx[param_band], *cx_imag_e, imag_buffer_fx, output_e, cx_imag_fx[param_band], &tmp2_e, nchan_in * nchan_in, 1 ); + v_add_fixed_me( cx_imag_fx[param_band], *cx_imag_e, imag_buffer_fx, output_e, cx_imag_fx[param_band], &tmp2_e, imult1616( nchan_in, nchan_in ), 1 ); cx_init_e[param_band] = tmp1_e; move16(); @@ -848,10 +845,10 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_collect_slot_fx( FOR( j = 0; j < PARAM_MC_MAX_TRANSPORT_CHANS * PARAM_MC_MAX_TRANSPORT_CHANS; j++ ) { L_tmp = BASOP_Util_Add_Mant32Exp( cx_fx[i][j], cx_init_e[i], 0, 0, &tmp1_e ); - cx_fx[i][j] = L_shr( L_tmp, tmp1 - tmp1_e ); + cx_fx[i][j] = L_shr( L_tmp, sub( tmp1, tmp1_e ) ); move32(); L_tmp = BASOP_Util_Add_Mant32Exp( cx_imag_fx[i][j], cx_init_imag_e[i], 0, 0, &tmp2_e ); - cx_imag_fx[i][j] = L_shr( L_tmp, tmp2 - tmp2_e ); + cx_imag_fx[i][j] = L_shr( L_tmp, sub( tmp2, tmp2_e ) ); move32(); } } @@ -1008,8 +1005,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( Word16 param_band_idx, band, ch_idx; Word16 have_residual; Word16 brange[2]; - DIRAC_OUTPUT_SYNTHESIS_COV_STATE h_synthesis_state = hParamMC->h_output_synthesis_cov_state; - + DIRAC_OUTPUT_SYNTHESIS_COV_STATE h_synthesis_state; Word32 mixing_matrix_smooth_fx[MAX_CICP_CHANNELS * PARAM_MC_MAX_TRANSPORT_CHANS]; Word16 mixing_matrix_smooth_e; Word32 mixing_matrix_res_smooth_fx[MAX_CICP_CHANNELS * MAX_CICP_CHANNELS]; @@ -1025,6 +1021,8 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( Word32 diff_f_real_fx[MAX_CICP_CHANNELS]; Word32 diff_f_imag_fx[MAX_CICP_CHANNELS]; + h_synthesis_state = hParamMC->h_output_synthesis_cov_state; + set_zero_fx( input_f_real_fx, PARAM_MC_MAX_TRANSPORT_CHANS ); set_zero_fx( input_f_imag_fx, PARAM_MC_MAX_TRANSPORT_CHANS ); set_zero_fx( output_f_real_fx, MAX_CICP_CHANNELS ); @@ -1039,37 +1037,39 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( move16(); brange[0] = hParamMC->band_grouping[param_band_idx]; move16(); - brange[1] = hParamMC->band_grouping[param_band_idx + 1]; + brange[1] = hParamMC->band_grouping[add( param_band_idx, 1 )]; move16(); - IF( brange[0] < hParamMC->h_output_synthesis_params.max_band_decorr ) + if ( LT_16( brange[0], hParamMC->h_output_synthesis_params.max_band_decorr ) ) { have_residual = 1; move16(); } - v_multc_fixed( mixing_matrix_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_smooth_fx, nY * nX ); + v_multc_fixed( mixing_matrix_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_smooth_fx, imult1616( nY, nX ) ); mixing_matrix_smooth_e = mixing_matrix_e[param_band_idx]; // interpolator is W16 move16(); - v_multc_fixed( h_synthesis_state.mixing_matrix_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, nY * nX ); + v_multc_fixed( h_synthesis_state.mixing_matrix_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, imult1616( nY, nX ) ); mixing_matrix_buffer_e = h_synthesis_state.mixing_matrix_old_exp[param_band_idx]; // interpolator is W16 + move16(); - v_add_fixed_me( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_smooth_fx, &mixing_matrix_smooth_e, nY * nX, 0 ); + v_add_fixed_me( mixing_matrix_smooth_fx, mixing_matrix_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_smooth_fx, &mixing_matrix_smooth_e, imult1616( nY, nX ), 0 ); IF( have_residual ) { /* residual mixing matrix interpolation*/ - v_multc_fixed( mixing_matrix_res_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_res_smooth_fx, nY * nY ); + v_multc_fixed( mixing_matrix_res_fx[param_band_idx], L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ), mixing_matrix_res_smooth_fx, imult1616( nY, nY ) ); mixing_matrix_res_smooth_e = mixing_matrix_res_e[param_band_idx]; // interpolator is W16 + move16(); - set_zero_fx( mixing_matrix_buffer_fx, nY * nY ); - v_multc_fixed( h_synthesis_state.mixing_matrix_res_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, nY * nY ); + set_zero_fx( mixing_matrix_buffer_fx, imult1616( nY, nY ) ); + v_multc_fixed( h_synthesis_state.mixing_matrix_res_old_fx[param_band_idx], L_sub( ONE_IN_Q31, L_deposit_h( hParamMC->h_output_synthesis_params.interpolator_fx[slot_idx_tot] ) ), mixing_matrix_buffer_fx, imult1616( nY, nY ) ); mixing_matrix_buffer_e = h_synthesis_state.mixing_matrix_res_old_exp[param_band_idx]; // interpolator is W16 + move16(); - - v_add_fixed_me( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_res_smooth_fx, &mixing_matrix_res_smooth_e, nY * nY, 0 ); + v_add_fixed_me( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, mixing_matrix_buffer_fx, mixing_matrix_buffer_e, mixing_matrix_res_smooth_fx, &mixing_matrix_res_smooth_e, imult1616( nY, nY ), 0 ); } @@ -1080,7 +1080,7 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( IF( have_residual ) { /* collect diffuse prototypes */ - assert( band < hParamMC->h_output_synthesis_params.max_band_decorr ); + assert( LT_16( band, hParamMC->h_output_synthesis_params.max_band_decorr ) ); FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { diff_f_real_fx[ch_idx] = Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band]; // Q6 @@ -1092,11 +1092,11 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( /* apply residual mixing */ matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_real_fx, 25, nY, 1, 0, output_f_real_fx, &output_f_real_e ); - scale_sig32( output_f_real_fx, nY, 6 - ( 31 - output_f_real_e ) ); + scale_sig32( output_f_real_fx, nY, sub( Q6, sub( Q31, output_f_real_e ) ) ); matrix_product_mant_exp_fx( mixing_matrix_res_smooth_fx, mixing_matrix_res_smooth_e, nY, nY, 0, diff_f_imag_fx, 25, nY, 1, 0, output_f_imag_fx, &output_f_imag_e ); - scale_sig32( output_f_imag_fx, nY, 6 - ( 31 - output_f_imag_e ) ); + scale_sig32( output_f_imag_fx, nY, sub( Q6, sub( Q31, output_f_imag_e ) ) ); FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { @@ -1121,9 +1121,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( FOR( ch_idx = 0; ch_idx < nX; ch_idx++ ) { - input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; // Q6 + input_f_real_fx[ch_idx] = Cldfb_RealBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; // Q6 move32(); - input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[ch_idx * hParamMC->num_freq_bands + band]; + input_f_imag_fx[ch_idx] = Cldfb_ImagBuffer_in_fx[add( imult1616( ch_idx, hParamMC->num_freq_bands ), band )]; move32(); } @@ -1140,7 +1140,9 @@ void ivas_dirac_dec_output_synthesis_cov_param_mc_synthesise_slot_fx( FOR( ch_idx = 0; ch_idx < nY; ch_idx++ ) { Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add( Cldfb_RealBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_real_fx[ch_idx] ); + move32(); Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band] = L_add( Cldfb_ImagBuffer_fx[ch_idx][slot_idx_sfr][band], output_f_imag_fx[ch_idx] ); + move32(); } } } @@ -1436,7 +1438,7 @@ Word16 computeMixingMatrices_fx( Word16 *Cr_e ) { Word16 i, j; - Word16 out = EXIT_SUCCESS; + Word16 out; Word16 nL, nC; Word16 lengthCx = num_inputs; Word16 lengthCy = num_outputs; @@ -1505,6 +1507,8 @@ Word16 computeMixingMatrices_fx( Word32 *Cr_p_fx, *Cy_tilde_p_fx, *Cy_p_fx; push_wmops( "dirac_cov_mix_mat" ); + out = EXIT_SUCCESS; + move16(); set32_fx( svd_s_buffer_fx, 0, MAX_OUTPUT_CHANNELS ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) @@ -1515,9 +1519,9 @@ Word16 computeMixingMatrices_fx( } - Copy32( Q, Q_fx, lengthCy * lengthCx ); - Copy32( Cx, Cx_fx, lengthCx * lengthCx ); - Copy32( Cy, Cy_fx, lengthCy * lengthCy ); + Copy32( Q, Q_fx, imult1616( lengthCy, lengthCx ) ); + Copy32( Cx, Cx_fx, imult1616( lengthCx, lengthCx ) ); + Copy32( Cy, Cy_fx, imult1616( lengthCy, lengthCy ) ); Q_e = Q_fx_e; move16(); @@ -1546,23 +1550,32 @@ Word16 computeMixingMatrices_fx( FOR( j = 0; j < lengthCy; ++j ) { tmp_e = svd_s_buffer_fx_e; + move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); - Ky_fx_e[i + j * lengthCy] = +tmp_e; + Ky_fx[add( i, imult1616( j, lengthCy ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + move32(); + Ky_fx_e[add( i, imult1616( j, lengthCy ) )] = tmp_e; + move16(); } } exp = Ky_fx_e[0]; + move16(); FOR( i = 1; i < lengthCy * lengthCy; i++ ) { - IF( exp < Ky_fx_e[i] ) - exp = Ky_fx_e[i]; + if ( LT_16( exp, Ky_fx_e[i] ) ) + { + exp = Ky_fx_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Ky_fx[i] = L_shr( Ky_fx[i], exp - Ky_fx_e[i] ); + Ky_fx[i] = L_shr( Ky_fx[i], sub( exp, Ky_fx_e[i] ) ); + move32(); Ky_fx_e[i] = exp; + move16(); } @@ -1581,22 +1594,30 @@ Word16 computeMixingMatrices_fx( FOR( j = 0; j < lengthCx; ++j ) { tmp_e = svd_s_buffer_fx_e; + move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); - Kx_fx[i + j * lengthCx] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); - Kx_fx_e[i + j * lengthCx] = tmp_e; + Kx_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + move32(); + Kx_fx_e[add( i, imult1616( j, lengthCx ) )] = tmp_e; + move16(); } } exp = Kx_fx_e[0]; + move16(); FOR( i = 1; i < lengthCx * lengthCx; i++ ) { - IF( exp < Kx_fx_e[i] ) - exp = Kx_fx_e[i]; + if ( LT_16( exp, Kx_fx_e[i] ) ) + { + exp = Kx_fx_e[i]; + move16(); + } } FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - Kx_fx[i] = L_shr( Kx_fx[i], exp - Kx_fx_e[i] ); + Kx_fx[i] = L_shr( Kx_fx[i], sub( exp, Kx_fx_e[i] ) ); + move32(); Kx_fx_e[i] = exp; move16(); } @@ -1607,26 +1628,30 @@ Word16 computeMixingMatrices_fx( tmp_e = svd_s_buffer_fx_e; move16(); svd_s_buffer_fx[i] = Sqrt32( svd_s_buffer_fx[i], &tmp_e ); + move32(); svd_s_buffer_e[i] = tmp_e; move16(); } // making the Q common - Word16 max = svd_s_buffer_e[0]; + Word16 max_e; + max_e = svd_s_buffer_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { - IF( max < svd_s_buffer_e[i] ) + if ( LT_16( max_e, svd_s_buffer_e[i] ) ) { - max = svd_s_buffer_e[i]; + max_e = svd_s_buffer_e[i]; move16(); } } FOR( i = 0; i < lengthCx; i++ ) { - svd_s_buffer_fx[i] = L_shr( svd_s_buffer_fx[i], ( max - svd_s_buffer_e[i] ) ); + svd_s_buffer_fx[i] = L_shr( svd_s_buffer_fx[i], ( max_e - svd_s_buffer_e[i] ) ); + move32(); } - svd_s_buffer_fx_e = max; + svd_s_buffer_fx_e = max_e; move16(); @@ -1639,16 +1664,19 @@ Word16 computeMixingMatrices_fx( move16(); L_tmp = Mpy_32_32( limit_fx, reg_Sx_fx ); - limit_e = limit_e + reg_Sx_e; + limit_e = add( limit_e, reg_Sx_e ); limit_fx = L_add( L_tmp, EPSILON_FX ); FOR( i = 0; i < lengthCx; ++i ) { svd_s_buffer_e[i] = svd_s_buffer_fx_e; + move16(); IF( BASOP_Util_Cmp_Mant32Exp( svd_s_buffer_fx[i], svd_s_buffer_fx_e, limit_fx, limit_e ) < 0 ) { svd_s_buffer_fx[i] = limit_fx; + move32(); svd_s_buffer_e[i] = limit_e; + move16(); } } @@ -1667,11 +1695,13 @@ Word16 computeMixingMatrices_fx( { Word16 scale, reg_fac_fx; reg_fac_fx = BASOP_Util_Divide3232_Scale( 1, svd_s_buffer_fx[i], &scale ); - scale = scale + ( 31 - svd_s_buffer_e[i] ); + scale = add( scale, sub( Q31, svd_s_buffer_e[i] ) ); FOR( j = 0; j < lengthCx; ++j ) { - Kx_reg_inv_fx[i + j * lengthCx] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); - Kx_reg_inv_e[i + j * lengthCx] = scale; + Kx_reg_inv_fx[add( i, imult1616( j, lengthCx ) )] = Mpy_32_16_1( svd_u_buffer_fx[j][i], reg_fac_fx ); + move32(); + Kx_reg_inv_e[add( i, imult1616( j, lengthCx ) )] = scale; + move16(); } } @@ -1679,14 +1709,17 @@ Word16 computeMixingMatrices_fx( move16(); FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - IF( exp < Kx_reg_inv_e[i] ) - exp = Kx_reg_inv_e[i]; - move16(); + if ( LT_16( exp, Kx_reg_inv_e[i] ) ) + { + exp = Kx_reg_inv_e[i]; + move16(); + } } FOR( i = 0; i < lengthCx * lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], exp - Kx_reg_inv_e[i] ); + Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], sub( exp, Kx_reg_inv_e[i] ) ); + move32(); Kx_reg_inv_e[i] = exp; move16(); } @@ -1699,27 +1732,30 @@ Word16 computeMixingMatrices_fx( matrix_product_mant_exp_fx( Q_fx, Q_e, lengthCy, lengthCx, 0, Cx_fx, Cx_fx_e, lengthCx, lengthCx, 0, Q_Cx_fx, &Q_Cx_e ); - Word16 guard_bits = find_guarded_bits_fx( lengthCx + 1 ); + Word16 guard_bits; + guard_bits = find_guarded_bits_fx( lengthCx + 1 ); FOR( i = 0; i < lengthCy * lengthCx; ++i ) { - IF( Q_Cx_e > Q_e ) + IF( GT_16( Q_Cx_e, Q_e ) ) { Q_fx[i] = L_shr( Q_fx[i], guard_bits ); + move32(); } ELSE { Q_Cx_fx[i] = L_shr( Q_Cx_fx[i], guard_bits ); + move32(); } } - IF( Q_Cx_e > Q_e ) + IF( GT_16( Q_Cx_e, Q_e ) ) { - Q_e += guard_bits; + Q_e = add( Q_e, guard_bits ); } ELSE { - Q_Cx_e += guard_bits; + Q_Cx_e = add( Q_Cx_e, guard_bits ); } matrix_product_diag_fx( Q_Cx_fx, Q_Cx_e, lengthCy, lengthCx, 0, Q_fx, Q_e, lengthCy, lengthCx, 1, Cy_hat_diag_fx, &Cy_hat_diag_e ); @@ -1737,7 +1773,8 @@ Word16 computeMixingMatrices_fx( L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); limit_fx = L_add( L_tmp, EPSILON_FX ); - limit_e = limit_e + reg_ghat_e; + limit_e = add( limit_e, reg_ghat_e ); + move16(); } @@ -1753,8 +1790,8 @@ Word16 computeMixingMatrices_fx( move16(); } - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + i * lengthCy], Cy_hat_diag_fx[i], &exp ); - exp = exp + ( Cy_fx_e - Cy_hat_diag_buff_e[i] ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], Cy_hat_diag_fx[i], &exp ); + exp = add( exp, sub( Cy_fx_e, Cy_hat_diag_buff_e[i] ) ); L_tmp = Sqrt32( L_deposit_h( tmp ), &exp ); G_hat_fx[i] = L_tmp; move32(); @@ -1766,13 +1803,17 @@ Word16 computeMixingMatrices_fx( move16(); FOR( i = 1; i < lengthCy; i++ ) { - IF( exp < G_hat_buff_e[i] ) - exp = G_hat_buff_e[i]; + if ( LT_16( exp, G_hat_buff_e[i] ) ) + { + exp = G_hat_buff_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy; i++ ) { - G_hat_fx[i] = L_shr( G_hat_fx[i], exp - G_hat_buff_e[i] ); + G_hat_fx[i] = L_shr( G_hat_fx[i], sub( exp, G_hat_buff_e[i] ) ); + move32(); } G_hat_e = exp; @@ -1790,7 +1831,7 @@ Word16 computeMixingMatrices_fx( matrix_product_mant_exp_fx( mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCy, 0, Ky_fx, Ky_fx_e[0], lengthCy, lengthCy, 0, mat_mult_buffer1_fx, &mat_mult_buffer1_e ); - IF( lengthCx < lengthCy ) + IF( LT_16( lengthCx, lengthCy ) ) { mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, lengthCy, 1 ); @@ -1831,7 +1872,9 @@ Word16 computeMixingMatrices_fx( svdMat2mat_fx( svd_u_buffer_fx, mat_mult_buffer2_fx, lengthCx, lengthCx ); mat_mult_buffer1_e = 0; + move16(); mat_mult_buffer2_e = 0; + move16(); matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, @@ -1861,7 +1904,9 @@ Word16 computeMixingMatrices_fx( FOR( i = 0; i < lengthCy * lengthCy; i++ ) { Cy_fx[i] = L_shr( Cy_p_fx[i], exp - Cy_fx_e ); + move32(); Cy_tilde_p_fx[i] = L_shr( Cy_tilde_p_fx[i], exp - mat_mult_buffer2_e ); + move32(); } Cy_fx_e = exp; move16(); @@ -1872,14 +1917,18 @@ Word16 computeMixingMatrices_fx( FOR( j = 0; j < lengthCy; ++j ) { - *( Cr_p_fx++ ) = *( Cy_p_fx++ ) - *( Cy_tilde_p_fx++ ); + *( Cr_p_fx ) = L_sub( *( Cy_p_fx ), *( Cy_tilde_p_fx ) ); + move32(); + Cr_p_fx++; + Cy_p_fx++; + Cy_tilde_p_fx++; } /* Avoid Meaningless negative main diagonal elements */ - IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[i + i * lengthCy], exp, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cr_fx[add( i, imult1616( i, lengthCy ) )], exp, 0, 0 ) < 0 ) { - Cr_fx[i + i * lengthCy] = 0; - move16(); + Cr_fx[add( i, imult1616( i, lengthCy ) )] = 0; + move32(); } } @@ -1890,7 +1939,7 @@ Word16 computeMixingMatrices_fx( * Energy Compensation *-----------------------------------------------------------------*/ - IF( energy_compensation_flag == 1 ) + IF( EQ_16( energy_compensation_flag, 1 ) ) { adj_fx_p = svd_s_buffer_fx; Cy_tilde_p_fx = mat_mult_buffer2_fx; @@ -1899,7 +1948,7 @@ Word16 computeMixingMatrices_fx( { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[i + i * lengthCy], mat_mult_buffer2_e, 0, 0 ) < 0 ) + IF( BASOP_Util_Cmp_Mant32Exp( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], mat_mult_buffer2_e, 0, 0 ) < 0 ) { adj_fx_p[i] = 1073741824; move32(); @@ -1908,8 +1957,8 @@ Word16 computeMixingMatrices_fx( } ELSE { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + lengthCy * i], L_add( Cy_tilde_p_fx[i + i * lengthCy], EPSILON_FX ), &exp ); - exp = exp + ( Cy_fx_e - mat_mult_buffer2_e ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( i, lengthCy ) )], L_add( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], EPSILON_FX ), &exp ); + exp = add( exp, sub( Cy_fx_e, mat_mult_buffer2_e ) ); L_tmp = L_deposit_h( tmp ); L_tmp = Sqrt32( L_tmp, &exp ); adj_fx_p[i] = L_tmp; @@ -1928,22 +1977,27 @@ Word16 computeMixingMatrices_fx( } exp = adj_e[0]; + move16(); FOR( i = 1; i < lengthCy; i++ ) { - IF( exp < adj_e[i] ) - exp = adj_e[i]; + if ( LT_16( exp, adj_e[i] ) ) + { + exp = adj_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], exp - adj_e[i] ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( exp, adj_e[i] ) ); + move32(); } adj_fx_e = exp; move16(); diag_matrix_product_fx( adj_fx, adj_fx_e, lengthCy, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, lengthCx * lengthCy ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCx, lengthCy ) ); mixing_matrix_e = mat_mult_buffer3_e; move16(); } @@ -2172,9 +2226,11 @@ Word16 computeMixingMatricesResidual_fx( Word16 *mixing_matrix_ret_e ) { Word16 i, j; - Word16 out = EXIT_SUCCESS; - Word16 lengthCx = extract_l( num_outputs ); - Word16 lengthCy = extract_l( num_outputs ); + Word16 out, lengthCx, lengthCy; + out = EXIT_SUCCESS; + move16(); + lengthCx = extract_l( num_outputs ); + lengthCy = extract_l( num_outputs ); Word32 svd_in_buffer_fx[MAX_OUTPUT_CHANNELS][MAX_OUTPUT_CHANNELS]; Word32 mat_mult_buffer2_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; @@ -2189,6 +2245,7 @@ Word16 computeMixingMatricesResidual_fx( Word32 adj_fx[MAX_OUTPUT_CHANNELS]; Word32 mat_mult_buffer3_fx[MAX_OUTPUT_CHANNELS * MAX_OUTPUT_CHANNELS]; Word16 mixing_matrix_e = 0, mat_mult_buffer1_e, adj_e, mat_mult_buffer3_e, mat_mult_buffer2_e; + move16(); #ifdef MSAN_FIX Word32 svd_s_buffer_fx[MAX_OUTPUT_CHANNELS] = { 0 }; @@ -2243,22 +2300,29 @@ Word16 computeMixingMatricesResidual_fx( FOR( j = 0; j < lengthCy; ++j ) { tmp_e = svd_s_buffer_fx_e; + move16(); L_tmp = Sqrt32( svd_s_buffer_fx[j], &tmp_e ); Ky_fx[i + j * lengthCy] = Mpy_32_32( svd_u_buffer_fx[i][j], L_tmp ); + move32(); Ky_fx_e[i + j * lengthCy] = tmp_e; + move16(); } } exp = Ky_fx_e[0]; + move16(); FOR( i = 1; i < lengthCy * lengthCy; i++ ) { - IF( exp < Ky_fx_e[i] ) - exp = Ky_fx_e[i]; + if ( LT_16( exp, Ky_fx_e[i] ) ) + { + exp = Ky_fx_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy * lengthCy; i++ ) { - Ky_fx[i] = L_shr( Ky_fx[i], exp - Ky_fx_e[i] ); + Ky_fx[i] = L_shr( Ky_fx[i], sub( exp, Ky_fx_e[i] ) ); Ky_fx_e[i] = exp; move16(); } @@ -2284,15 +2348,20 @@ Word16 computeMixingMatricesResidual_fx( } exp = Kx_fx_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { - IF( exp < Kx_fx_e[i] ) - exp = Kx_fx_e[i]; + if ( LT_16( exp, Kx_fx_e[i] ) ) + { + exp = Kx_fx_e[i]; + move16(); + } } FOR( i = 0; i < lengthCx; i++ ) { Kx_fx[i] = L_shr( Kx_fx[i], exp - Kx_fx_e[i] ); + move32(); Kx_fx_e[i] = exp; move16(); } @@ -2310,24 +2379,26 @@ Word16 computeMixingMatricesResidual_fx( L_tmp = L_add( L_tmp, EPSILLON_FX ); limit_fx = L_tmp; move16(); - limit_e = limit_e + reg_Sx_e; + limit_e = add( limit_e, reg_Sx_e ); FOR( i = 0; i < lengthCx; ++i ) { IF( BASOP_Util_Cmp_Mant32Exp( Kx_fx[i], Kx_fx_e[0], limit_fx, limit_e ) > 0 ) { div_tmp = Kx_fx[i]; + move32(); exp = Kx_fx_e[0]; move16(); } ELSE { div_tmp = limit_fx; + move32(); exp = limit_e; move16(); } tmp = BASOP_Util_Divide3232_Scale( 1073741824, div_tmp, &scale ); - scale = scale + ( 1 - exp ); + scale = add( scale, sub( Q1, exp ) ); Kx_reg_inv_fx[i] = L_deposit_h( tmp ); Kx_reg_inv_e[i] = scale; @@ -2335,15 +2406,20 @@ Word16 computeMixingMatricesResidual_fx( } exp = Kx_reg_inv_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { - IF( exp < Kx_reg_inv_e[i] ) - exp = Kx_reg_inv_e[i]; + if ( LT_16( exp, Kx_reg_inv_e[i] ) ) + { + exp = Kx_reg_inv_e[i]; + move16(); + } } FOR( i = 0; i < lengthCx; i++ ) { - Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], exp - Kx_reg_inv_e[i] ); + Kx_reg_inv_fx[i] = L_shr( Kx_reg_inv_fx[i], sub( exp, Kx_reg_inv_e[i] ) ); + move32(); } Kx_reg_inv_fx_e = exp; move16(); @@ -2365,6 +2441,7 @@ Word16 computeMixingMatricesResidual_fx( /* Computing Cy_hat_diag */ Copy32( Cx_fx, Cy_hat_diag_fx, extract_l( num_outputs ) ); Cy_hat_diag_e = Cx_e; + move16(); FOR( i = 0; i < lengthCy; ++i ) { @@ -2379,12 +2456,13 @@ Word16 computeMixingMatricesResidual_fx( L_tmp = Mpy_32_32( limit_fx, reg_ghat_fx ); limit_fx = L_add( L_tmp, EPSILON_FX ); - limit_e = limit_e + reg_ghat_e; + limit_e = add( limit_e, reg_ghat_e ); /* Computing G_hat */ FOR( i = 0; i < lengthCy; ++i ) { Cy_hat_diag_fx_e[i] = Cy_hat_diag_e; + move16(); IF( BASOP_Util_Cmp_Mant32Exp( limit_fx, limit_e, Cy_hat_diag_fx[i], Cy_hat_diag_e ) > 0 ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ { Cy_hat_diag_fx[i] = limit_fx; @@ -2393,7 +2471,7 @@ Word16 computeMixingMatricesResidual_fx( move16(); } tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + i * lengthCy], Cy_hat_diag_fx[i], &scale ); - scale = scale + ( Cy_fx_e - Cy_hat_diag_fx_e[i] ); + scale = add( scale, sub( Cy_fx_e, Cy_hat_diag_fx_e[i] ) ); L_tmp = Sqrt32( L_deposit_h( tmp ), &scale ); G_hat_fx[i] = L_tmp; @@ -2410,18 +2488,23 @@ Word16 computeMixingMatricesResidual_fx( { L_tmp = Mpy_32_32( Kx_fx[i], G_hat_fx[i] ); Kx_fx[i] = L_tmp; - Kx_fx_e[i] = Kx_fx_e[i] + G_hat_e[i]; + move32(); + Kx_fx_e[i] = add( Kx_fx_e[i], G_hat_e[i] ); + move16(); } FOR( i = 0; i < num_outputs; i++ ) { - Word32 fac_fx = Kx_fx[i]; + Word32 fac_fx; + fac_fx = Kx_fx[i]; + move32(); FOR( j = 0; j < num_outputs; j++ ) { - L_tmp = Mpy_32_32( Ky_fx[i + j * num_outputs], fac_fx ); - mat_mult_buffer1_fx[i + j * num_outputs] = L_tmp; - mat_mult_buffer1_buff_e[i + j * num_outputs] = extract_l( L_add( Ky_fx_e[i + j * num_outputs], Kx_fx_e[i] ) ); + L_tmp = Mpy_32_32( Ky_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); + mat_mult_buffer1_fx[add( i, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + move32(); + mat_mult_buffer1_buff_e[add( i, imult1616( j, extract_l( num_outputs ) ) )] = extract_l( L_add( Ky_fx_e[add( i, imult1616( j, extract_l( num_outputs ) ) )], Kx_fx_e[i] ) ); } } @@ -2429,22 +2512,21 @@ Word16 computeMixingMatricesResidual_fx( move16(); FOR( i = 1; i < num_outputs * num_outputs; i++ ) { - IF( mat_mult_buffer1_e < mat_mult_buffer1_buff_e[i] ) - mat_mult_buffer1_e = mat_mult_buffer1_buff_e[i]; + if ( LT_16( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ) + { + mat_mult_buffer1_e = mat_mult_buffer1_buff_e[i]; + move16(); + } } FOR( i = 0; i < num_outputs * num_outputs; i++ ) { - mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], mat_mult_buffer1_e - mat_mult_buffer1_buff_e[i] ); + mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], sub( mat_mult_buffer1_e, mat_mult_buffer1_buff_e[i] ) ); + move32(); } mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, lengthCy, 0 ); - /*FOR ( Word32 g = 0; g < lengthCx; g++ ) - { - me2f_buf( ( svd_in_buffer_fx[g] ), mat_mult_buffer1_e, ( svd_in_buffer[g] ), lengthCy ); - }*/ - svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, lengthCx, lengthCy ); /* Actually Processing P */ @@ -2468,13 +2550,17 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < num_outputs; i++ ) { - Word32 fac_fx = Kx_reg_inv_fx[i]; + Word32 fac_fx; + fac_fx = Kx_reg_inv_fx[i]; + move32(); FOR( j = 0; j < num_outputs; j++ ) { - L_tmp = Mpy_32_32( mat_mult_buffer1_fx[j + i * num_outputs], fac_fx ); - mixing_matrix_fx[j + i * num_outputs] = L_tmp; - mixing_matrix_e = mat_mult_buffer1_e + Kx_reg_inv_fx_e; + L_tmp = Mpy_32_32( mat_mult_buffer1_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )], fac_fx ); + mixing_matrix_fx[add( j, imult1616( j, extract_l( num_outputs ) ) )] = L_tmp; + move32(); + mixing_matrix_e = add( mat_mult_buffer1_e, Kx_reg_inv_fx_e ); + move16(); } } @@ -2490,23 +2576,25 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy * lengthCx; ++i ) { - IF( mat_mult_buffer1_e > mixing_matrix_e ) + IF( GT_16( mat_mult_buffer1_e, mixing_matrix_e ) ) { mixing_matrix_fx[i] = L_shr( mixing_matrix_fx[i], guard_bits ); + move32(); } ELSE { mat_mult_buffer1_fx[i] = L_shr( mat_mult_buffer1_fx[i], guard_bits ); + move32(); } } - IF( mat_mult_buffer1_e > mixing_matrix_e ) + IF( GT_16( mat_mult_buffer1_e, mixing_matrix_e ) ) { - mixing_matrix_e += guard_bits; + mixing_matrix_e = add( mixing_matrix_e, guard_bits ); } ELSE { - mat_mult_buffer1_e += guard_bits; + mat_mult_buffer1_e = add( mat_mult_buffer1_e, guard_bits ); } matrix_product_diag_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, lengthCy, lengthCx, 0, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 1, Cy_tilde_fx, &Cy_tilde_e ); @@ -2519,10 +2607,11 @@ Word16 computeMixingMatricesResidual_fx( FOR( i = 0; i < lengthCy; ++i ) { - tmp = BASOP_Util_Divide3232_Scale( Cy_fx[i + lengthCy * i], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); - scale = scale + ( Cy_fx_e - Cy_tilde_e ); + tmp = BASOP_Util_Divide3232_Scale( Cy_fx[add( i, imult1616( lengthCy, i ) )], L_add( Cy_tilde_fx[i], EPSILON_FX ), &scale ); + scale = add( scale, sub( Cy_fx_e, Cy_tilde_e ) ); adj_fx_p[i] = Sqrt32( L_deposit_h( tmp ), &scale ); adj_buff_e[i] = scale; + move16(); IF( BASOP_Util_Cmp_Mant32Exp( adj_fx_p[i], scale, 1073741824, 3 ) > 0 ) { adj_fx_p[i] = 1073741824; @@ -2533,21 +2622,26 @@ Word16 computeMixingMatricesResidual_fx( } adj_e = adj_buff_e[0]; + move16(); FOR( i = 1; i < lengthCy; i++ ) { - IF( adj_e < adj_buff_e[i] ) - adj_e = adj_buff_e[i]; + if ( LT_16( adj_e, adj_buff_e[i] ) ) + { + adj_e = adj_buff_e[i]; + move16(); + } } FOR( i = 0; i < lengthCy; i++ ) { - adj_fx[i] = L_shr( adj_fx_p[i], adj_e - adj_buff_e[i] ); + adj_fx[i] = L_shr( adj_fx_p[i], sub( adj_e, adj_buff_e[i] ) ); + move32(); } diag_matrix_product_fx( adj_fx, adj_e, lengthCy, mixing_matrix_fx, mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, lengthCy * lengthCx ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCy, lengthCx ) ); *mixing_matrix_ret_e = mat_mult_buffer3_e; move16(); @@ -2612,21 +2706,27 @@ Word16 computeMixingMatricesISM_fx( push_wmops( "dirac_cov_mix_mat" ); out = EXIT_SUCCESS; + move32(); lengthCx = num_inputs; + move16(); lengthCy = num_outputs; + move16(); FOR( i = 0; i < lengthCy * lengthCx; i++ ) { - IF( Q_16fx[i] == MAX_16 ) + IF( EQ_16( Q_16fx[i], MAX_16 ) ) { Q_fx[i] = MAX_32; + move32(); } ELSE { Q_fx[i] = L_deposit_h( Q_16fx[i] ); + move32(); } } Q_e = 0; + move16(); set32_fx( svd_s_buffer_fx, 0, MAX_OUTPUT_CHANNELS ); FOR( i = 0; i < MAX_OUTPUT_CHANNELS; i++ ) { @@ -2643,6 +2743,7 @@ Word16 computeMixingMatricesISM_fx( set16_fx( temp_e, Cx_diag_e, lengthCx ); v_sqrt_fx( Cx_diag_fx, temp_e, Kx_fx, lengthCx ); Kx_e = temp_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { Kx_e = s_max( Kx_e, temp_e[i] ); @@ -2650,6 +2751,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCx; i++ ) { Kx_fx[i] = L_shr_r( Kx_fx[i], sub( Kx_e, temp_e[i] ) ); + move32(); } /* Regularization of Sx */ @@ -2658,11 +2760,22 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCx; ++i ) { - svd_s_buffer_fx[i] = ( ( Kx_fx[i] > limit_fx ) ? Kx_fx[i] : limit_fx ); + IF( GT_32( Kx_fx[i], limit_fx ) ) + { + svd_s_buffer_fx[i] = Kx_fx[i]; + move32(); + } + ELSE + { + svd_s_buffer_fx[i] = limit_fx; + move32(); + } } svd_s_buffer_fx_e = Kx_e; + move16(); limit_fx = 0; + move32(); /* regularized Kx-1 */ @@ -2670,18 +2783,25 @@ Word16 computeMixingMatricesISM_fx( { IF( svd_s_buffer_fx[i] ) { - Word32 reg_fac = BASOP_Util_Divide3232_Scale_cadence( MAX_32, svd_s_buffer_fx[i], &temp_e[i] ); + Word32 reg_fac; + reg_fac = BASOP_Util_Divide3232_Scale_cadence( MAX_32, svd_s_buffer_fx[i], &temp_e[i] ); Kx_reg_inv_fx[i] = reg_fac; + move32(); temp_e[i] = sub( temp_e[i], svd_s_buffer_fx_e ); + move16(); } ELSE { - Word32 reg_fac = BASOP_Util_Divide3232_Scale_cadence( MAX_32, EPSILON_FX_M, &temp_e[i] ); + Word32 reg_fac; + reg_fac = BASOP_Util_Divide3232_Scale_cadence( MAX_32, EPSILON_FX_M, &temp_e[i] ); Kx_reg_inv_fx[i] = reg_fac; + move32(); temp_e[i] = sub( temp_e[i], EPSILON_FX_E ); + move16(); } } Kx_reg_inv_e = temp_e[0]; + move16(); FOR( i = 1; i < lengthCx; i++ ) { Kx_reg_inv_e = s_max( Kx_reg_inv_e, temp_e[i] ); @@ -2689,6 +2809,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCx; i++ ) { Kx_reg_inv_fx[i] = L_shr_r( Kx_reg_inv_fx[i], sub( Kx_reg_inv_e, temp_e[i] ) ); + move32(); } /************************ normalization matrix G hat **********************/ @@ -2706,29 +2827,32 @@ Word16 computeMixingMatricesISM_fx( IF( GT_16( Q_Cx_e, Q_e ) ) { Q_fx[i] = L_shr( Q_fx[i], guard_bits ); + move32(); } ELSE { Q_Cx_fx[i] = L_shr( Q_Cx_fx[i], guard_bits ); + move32(); } } IF( GT_16( Q_Cx_e, Q_e ) ) { - Q_e += guard_bits; + Q_e = add( Q_e, guard_bits ); } ELSE { - Q_Cx_e += guard_bits; + Q_Cx_e = add( Q_Cx_e, guard_bits ); } matrix_product_diag_fx( Q_Cx_fx, Q_Cx_e, lengthCy, lengthCx, 0, Q_fx, Q_e, lengthCy, lengthCx, 1, Cy_hat_diag_fx, &Cy_hat_diag_e ); /* Computing Cy_hat_diag */ FOR( i = 0; i < lengthCy; ++i ) { - IF( GT_32( Cy_hat_diag_fx[i], limit_fx ) ) + if ( GT_32( Cy_hat_diag_fx[i], limit_fx ) ) { limit_fx = Cy_hat_diag_fx[i]; + move32(); } } @@ -2737,33 +2861,43 @@ Word16 computeMixingMatricesISM_fx( /* Computing G_hat */ FOR( i = 0; i < lengthCy; ++i ) { - IF( GT_32( limit_fx, Cy_hat_diag_fx[i] ) ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ + if ( GT_32( limit_fx, Cy_hat_diag_fx[i] ) ) /* Computing Cy_hat_diag = max(Cy_hat_diag,limit) */ { Cy_hat_diag_fx[i] = limit_fx; + move32(); } IF( Cy_diag_fx[i] ) { IF( Cy_hat_diag_fx[i] ) { G_hat_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_hat_diag_fx[i], &temp_e[i] ); + move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, Cy_hat_diag_e ) ); + move16(); G_hat_fx[i] = Sqrt32( G_hat_fx[i], &temp_e[i] ); + move32(); } ELSE { G_hat_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], EPSILON_FX_M, &temp_e[i] ); + move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, EPSILON_FX_E ) ); + move16(); G_hat_fx[i] = Sqrt32( G_hat_fx[i], &temp_e[i] ); + move32(); } } ELSE { G_hat_fx[i] = 0; + move32(); temp_e[i] = 0; + move16(); } // G_hat[i] = sqrtf( Cy_diag[i] / Cy_hat_diag[i] ); } G_hat_e = temp_e[0]; + move16(); FOR( i = 1; i < lengthCy; i++ ) { G_hat_e = s_max( G_hat_e, temp_e[i] ); @@ -2771,6 +2905,7 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; i++ ) { G_hat_fx[i] = L_shr_r( G_hat_fx[i], sub( G_hat_e, temp_e[i] ) ); + move32(); } /************************ Formulate optimal P **********************/ @@ -2787,7 +2922,9 @@ Word16 computeMixingMatricesISM_fx( mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, num_responses, 1 ); nL = num_responses; + move16(); nC = lengthCx; + move16(); svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_v_buffer_fx, svd_s_buffer_fx, svd_u_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); } ELSE @@ -2795,7 +2932,9 @@ Word16 computeMixingMatricesISM_fx( mat2svdMat_fx( mat_mult_buffer1_fx, svd_in_buffer_fx, lengthCx, num_responses, 0 ); nL = lengthCx; + move16(); nC = num_responses; + move16(); svd_fx( svd_in_buffer_fx, mat_mult_buffer1_e, svd_u_buffer_fx, svd_s_buffer_fx, svd_v_buffer_fx, &svd_s_buffer_fx_e, nL, nC ); } @@ -2804,8 +2943,10 @@ Word16 computeMixingMatricesISM_fx( /* can be skipped: lambda is always column-truncated identity matrix, so this operation just truncates V to num_input_channel columns */ svdMat2mat_fx( svd_v_buffer_fx, mat_mult_buffer1_fx, num_responses, lengthCx ); mat_mult_buffer1_e = 0; + move16(); svdMat2mat_fx( svd_u_buffer_fx, mat_mult_buffer2_fx, lengthCx, lengthCx ); mat_mult_buffer2_e = 0; + move16(); matrix_product_mant_exp_fx( mat_mult_buffer1_fx, mat_mult_buffer1_e, num_responses, lengthCx, 0, mat_mult_buffer2_fx, mat_mult_buffer2_e, lengthCx, lengthCx, 1, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); @@ -2829,43 +2970,56 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; ++i ) { /* Avoid correction for very small energies, main diagonal elements of Cy_tilde_p may be negative */ - IF( LT_32( Cy_tilde_p_fx[i + i * lengthCy], 0 ) ) + IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] < 0 ) { adj_fx[i] = MAX_32; + move32(); temp_e[i] = 0; + move16(); } ELSE { IF( Cy_diag_fx[i] ) { - IF( Cy_tilde_p_fx[i + i * lengthCy] ) + IF( Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )] ) { - adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[i + i * lengthCy], &temp_e[i] ); + adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], Cy_tilde_p_fx[add( i, imult1616( i, lengthCy ) )], &temp_e[i] ); + move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, mat_mult_buffer2_e ) ); + move16(); adj_fx[i] = Sqrt32( adj_fx[i], &temp_e[i] ); + move32(); } ELSE { adj_fx[i] = BASOP_Util_Divide3232_Scale_cadence( Cy_diag_fx[i], EPSILON_FX_M, &temp_e[i] ); + move32(); temp_e[i] = add( temp_e[i], sub( Cy_diag_e, EPSILON_FX_E ) ); + move16(); adj_fx[i] = Sqrt32( adj_fx[i], &temp_e[i] ); + move32(); } } ELSE { adj_fx[i] = 0; + move32(); temp_e[i] = 0; + move16(); } } // if ( adj[i] > 4.0f ) - IF( GT_16( BASOP_Util_Cmp_Mant32Exp( adj_fx[i], temp_e[i], MAX_32, 2 ), 0 ) ) + IF( BASOP_Util_Cmp_Mant32Exp( adj_fx[i], temp_e[i], MAX_32, 2 ) > 0 ) { adj_fx[i] = MAX_32; + move32(); temp_e[i] = 2; + move16(); } } adj_e = temp_e[0]; + move16(); FOR( i = 1; i < lengthCy; i++ ) { adj_e = s_max( adj_e, temp_e[i] ); @@ -2873,12 +3027,14 @@ Word16 computeMixingMatricesISM_fx( FOR( i = 0; i < lengthCy; i++ ) { adj_fx[i] = L_shr_r( adj_fx[i], sub( adj_e, temp_e[i] ) ); + move32(); } diag_matrix_product_fx( adj_fx, adj_e, lengthCy, mixing_matrix_fx, *mixing_matrix_e, lengthCy, lengthCx, 0, mat_mult_buffer3_fx, &mat_mult_buffer3_e ); - Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, lengthCy * lengthCx ); + Copy32( mat_mult_buffer3_fx, mixing_matrix_fx, imult1616( lengthCy, lengthCx ) ); *mixing_matrix_e = mat_mult_buffer3_e; + move16(); } pop_wmops(); -- GitLab From e6dbe88832c1cb30ea8ea2165f45a9c3ecd1bb65 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Wed, 19 Jun 2024 12:15:07 +0530 Subject: [PATCH 2/2] Clang formatting changes --- lib_dec/ivas_dirac_dec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index a740ef159..c5c65c8d1 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -2842,8 +2842,8 @@ void ivas_qmetadata_to_dirac_fx( move16(); } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) @@ -3184,8 +3184,8 @@ void ivas_qmetadata_to_dirac( tmp_write_idx_param_band = ( tmp_write_idx_param_band + 1 ) % hSpatParamRendCom->dirac_md_buffer_length; } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ for ( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) -- GitLab