diff --git a/apps/decoder.c b/apps/decoder.c index b846e30829f94a5f1337925fb2d80ed79d415d56..03c916518a15680cdf7b6d6aef1586bc01c9d230 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -514,7 +514,14 @@ cleanup: #ifdef DEBUG_SBA_AUDIO_DUMP IVAS_DEC_GetSbaDebugParams( hIvasDec, &numOutChannels, &numTransportChannels, &pca_ingest_channels ); #endif - +#ifdef FIX_235 + if ( arg.hrtfReaderEnabled ) + { + IVAS_DEC_HRTF_HANDLE hHrtfTD; + IVAS_DEC_GetHrtfHandle( hIvasDec, &hHrtfTD ); + dealloc_HRTF_binary( hHrtfTD ); + } +#endif IVAS_DEC_Close( &hIvasDec ); CustomLsReader_close( &hLsCustomReader ); hrtfFileReader_close( &hrtfReader ); diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ec86280ebee847e6aa45b503c7f798a535efd4bd..872b551ac0dc639b0f4b42d077aac5667f231c97 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5119,9 +5119,11 @@ void BSplineModelEvalDealloc( ModelEval_t *modelEval /* i : Model evaluation structure */ ); +#ifndef FIX_235 void BSplineModelEvalITDDealloc( ModelParamsITD_t *model /* i : Model parameters */ ); +#endif #ifdef TDREND_HRTF_TABLE_METHODS void TDREND_HRFILT_SetFiltSet( diff --git a/lib_com/options.h b/lib_com/options.h old mode 100644 new mode 100755 index 989143e5c6a61219c9a7b6e44aba6c68f691762f..c0b3836c169e78d5ff51b7af8f57f18594694e8d --- a/lib_com/options.h +++ b/lib_com/options.h @@ -151,6 +151,8 @@ #define FIX_265_MC_BRATE_SWITCHING /* Issue 265: fix use-of-uninitialized-value in MC bitrate switching */ #define FIX_ANGLE_WRAPPING /* Issue 244: Problems with angle wrapping*/ #define FIX_272_COV /* Issue 272: Cleanup for code coverage related to calls to ivas_binaural_cldfb() */ +#define FIX_235 /* Issue 235: Deallocation of HR filter memory separately for lib_rend (ROM) and lib_util (from file) */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 604953777f77b242c1e99ec9c6ea253bc125c7da..75cacbdcd7cb353915170c10067e0a7bf264d40e 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -1713,12 +1713,13 @@ void ivas_destroy_dec( } else if ( st_ivas->hHrtfTD != NULL ) { +#ifndef FIX_235 /* Case when HRTF filter is mistakenly specified but TD renderer was not active */ if ( st_ivas->hHrtfTD->ModelParams.UseItdModel && !st_ivas->hHrtfTD->ModelParams.modelROM ) { BSplineModelEvalITDDealloc( &st_ivas->hHrtfTD->ModelParamsITD ); } - +#endif BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index c2997eefc57d1d723a98000cebab9b15acee7f8b..056932f9bd830514d21ef967de424df78fd70433 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -210,12 +210,13 @@ ivas_error ivas_sba_dec_reinit( } else if ( st_ivas->hHrtfTD != NULL ) { +#ifndef FIX_235 /* Case when HRTF filter is mistakenly specified but TD renderer was not active */ if ( st_ivas->hHrtfTD->ModelParams.UseItdModel && !st_ivas->hHrtfTD->ModelParams.modelROM ) { BSplineModelEvalITDDealloc( &st_ivas->hHrtfTD->ModelParamsITD ); } - +#endif BSplineModelEvalDealloc( &st_ivas->hHrtfTD->ModelParams, &st_ivas->hHrtfTD->ModelEval ); ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); diff --git a/lib_rend/ivas_hrtf.c b/lib_rend/ivas_hrtf.c index 4cc9867a949175b8ab0d97092c26b6b314cc9012..347a060e9800e093e27a91f7d709922d5ca0e9c9 100644 --- a/lib_rend/ivas_hrtf.c +++ b/lib_rend/ivas_hrtf.c @@ -61,10 +61,8 @@ void BSplineModelEvalAlloc( ModelEval_t *modelEval /* i/o: Model evaluation structure */ ) { -#define WMC_TOOL_SKIP modelEval->hrfModL = (float *) malloc( model->K * sizeof( float ) ); modelEval->hrfModR = (float *) malloc( model->K * sizeof( float ) ); -#undef WMC_TOOL_SKIP return; } @@ -120,13 +118,11 @@ void DefaultBSplineModel( model->elevKSeq = (const float *) orange53_rom_elevKSeq; model->elevBsShape = (const float *) orange53_rom_elevBsShape; -#define WMC_TOOL_SKIP model->azimBsShape = (const float **) malloc( model->num_unique_azim_splines * sizeof( float * ) ); model->azimBsShape[0] = (const float *) orange53_rom_azimBsShape; model->azimKSeq = (float **) malloc( 18 * sizeof( float * ) ); model->azimKSeq[0] = (float *) malloc( 2 * sizeof( float * ) ); model->azimKSeq[17] = (float *) malloc( 2 * sizeof( float * ) ); -#undef WMC_TOOL_SKIP model->azimKSeq[0][0] = 0.0f; model->azimKSeq[17][0] = 0.0f; model->azimKSeq[0][1] = 360.0f; @@ -134,9 +130,7 @@ void DefaultBSplineModel( for ( i = 1; i < 17; i++ ) { -#define WMC_TOOL_SKIP model->azimKSeq[i] = (float *) malloc( model->azimDim2[i] * sizeof( float * ) ); /* azimDim2[i] = 91, i=2..15 */ -#undef WMC_TOOL_SKIP for ( j = 0; j < model->azimDim2[i]; j++ ) { model->azimKSeq[i][j] = (float) orange53_rom_azimSegSamples[0] * j; diff --git a/lib_rend/ivas_objectRenderer_hrFilt.c b/lib_rend/ivas_objectRenderer_hrFilt.c index ebb9cf19ef7091bcf703d1b739e33757b714d244..f71ae77a13417c90944d04e73ecc7038f298d939 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt.c +++ b/lib_rend/ivas_objectRenderer_hrFilt.c @@ -1064,6 +1064,10 @@ void HRTF_model_precalc( ModelParams_t *model /* i/o: HRTF model parameters */ ) { +#ifdef FIX_235 + int16_t sec_length; + int16_t i; +#else int16_t sec_length; int16_t i, k, j; float *pEL; @@ -1072,6 +1076,7 @@ void HRTF_model_precalc( const float *pAlphaR; float tmp; int16_t AlphaN; +#endif sec_length = model->K / HRTF_MODEL_N_SECTIONS; @@ -1087,6 +1092,7 @@ void HRTF_model_precalc( maximum_s( model->azimDim3, model->elevDim3, &model->azimDim3Max ); +#ifndef FIX_235 if ( !model->modelROM ) { AlphaN = model->AlphaN; @@ -1123,6 +1129,7 @@ void HRTF_model_precalc( model->EL = (const float *) model->EL_dyn; model->ER = (const float *) model->ER_dyn; } +#endif return; } @@ -1140,7 +1147,7 @@ void BSplineModelEvalDealloc( { /* Allocated in LoadBSplineBinary() */ int16_t i; - +#ifndef FIX_235 #define WMC_TOOL_SKIP if ( !model->modelROM ) { @@ -1177,11 +1184,27 @@ void BSplineModelEvalDealloc( free( modelEval->hrfModR ); } #undef WMC_TOOL_SKIP +#else + if ( model->modelROM ) + { + free( (void *) model->azimBsShape ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ + for ( i = 0; i < model->elevDim3; i++ ) + { + free( model->azimKSeq[i] ); + } + free( model->azimKSeq ); + if ( modelEval != NULL ) + { + free( modelEval->hrfModL ); + free( modelEval->hrfModR ); + } + } +#endif return; } - +#ifndef FIX_235 /*-------------------------------------------------------------------* * BSplineModelEvalITDDealloc() * @@ -1202,7 +1225,7 @@ void BSplineModelEvalITDDealloc( return; } - +#endif /*-------------------------------------------------------------------* * SkipSmallest_ValueIndex() diff --git a/lib_rend/ivas_objectRenderer_mix.c b/lib_rend/ivas_objectRenderer_mix.c index 6fa5270304acc9db20ffb2e93d03e6924069cbd7..98eca0b534f85bb06040320f5939db11186d005c 100644 --- a/lib_rend/ivas_objectRenderer_mix.c +++ b/lib_rend/ivas_objectRenderer_mix.c @@ -130,10 +130,12 @@ void TDREND_MIX_Dealloc( { if ( hBinRendererTd->HrFiltSet_p->FilterMethod == TDREND_HRFILT_Method_BSplineModel ) { +#ifndef FIX_235 if ( hBinRendererTd->HrFiltSet_p->ModelParams.UseItdModel && !hBinRendererTd->HrFiltSet_p->ModelParams.modelROM ) { BSplineModelEvalITDDealloc( &hBinRendererTd->HrFiltSet_p->ModelParamsITD ); } +#endif BSplineModelEvalDealloc( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); } else diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 9eddcdf305768ffd4031ac092700bd71ced9116b..15aa8d3c982d586415086c309d25fd2b0889d3f7 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -50,6 +50,14 @@ struct hrtfFileReader #define RESAMPLE_FACTOR_16_48 ( 16.0f / 48.0f ) #define RESAMPLE_FACTOR_32_48 ( 32.0f / 48.0f ) +#ifdef FIX_235 +/*---------------------------------------------------------------------* + * Local function declarations + *---------------------------------------------------------------------*/ + +static void HRTF_energy_sections_precalc( ModelParams_t *model ); +#endif + /*---------------------------------------------------------------------* * hrtfFileReader_open() * @@ -293,9 +301,17 @@ static ivas_error LoadBSplineBinary( } HRTF_model_precalc( model ); +#ifdef FIX_235 + HRTF_energy_sections_precalc( model ); +#endif HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; +#ifdef FIX_235 + HrFiltSet_p->ModelEval.hrfModL = (float *) malloc( model->K * sizeof( float ) ); + HrFiltSet_p->ModelEval.hrfModR = (float *) malloc( model->K * sizeof( float ) ); +#else BSplineModelEvalAlloc( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ); +#endif if ( HrFiltSet_p->ModelParams.UseItdModel ) { @@ -373,3 +389,124 @@ ivas_error load_HRTF_binary( return error; } + +#ifdef FIX_235 +/*---------------------------------------------------------------------* + * HRTF_energy_sections_precalc() + * + * Calculate energies of each section and store in model->EL/model->ER + *---------------------------------------------------------------------*/ + +static void HRTF_energy_sections_precalc( + ModelParams_t *model /* i/o: HRTF model parameters */ +) +{ + int16_t i, k, j; + float *pEL; + float *pER; + const float *pAlphaL; + const float *pAlphaR; + float tmp; + int16_t AlphaN; + + if ( !model->modelROM ) + { + AlphaN = model->AlphaN; + + /* Precalculated energies for each section and each row of the alpha matrices */ + model->EL_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); + model->ER_dyn = (float *) malloc( HRTF_MODEL_N_SECTIONS * AlphaN * sizeof( float ) ); + pEL = model->EL_dyn; + pER = model->ER_dyn; + for ( i = 0; i < HRTF_MODEL_N_SECTIONS; i++ ) + { + for ( j = 0; j < AlphaN; j++ ) /* rows of Alpha matrices */ + { + *pEL = 0.0f; + *pER = 0.0f; + + pAlphaL = &model->AlphaL[model->iSecFirst[i] * AlphaN + j]; + pAlphaR = &model->AlphaR[model->iSecFirst[i] * AlphaN + j]; + + for ( k = model->iSecFirst[i]; k < model->iSecLast[i]; k++ ) /* k within the sections */ + { + /* Energy calculation */ + tmp = *pAlphaL; + *pEL += tmp * tmp; + tmp = *pAlphaR; + *pER += tmp * tmp; + pAlphaL += AlphaN; + pAlphaR += AlphaN; + } + pEL++; + pER++; + } + } + model->EL = (const float *) model->EL_dyn; + model->ER = (const float *) model->ER_dyn; + } + + return; +} + + +/*---------------------------------------------------------------------* + * dealloc_HRTF_binary() + * + * Deallocated memory allocated by load_HRTF_binary + *---------------------------------------------------------------------*/ + +ivas_error dealloc_HRTF_binary( + IVAS_DEC_HRTF_HANDLE hHrtf /* i/o: HRTF handle */ +) +{ + int16_t i; + ivas_error error; + error = IVAS_ERR_OK; + + if ( !hHrtf->ModelParams.modelROM ) + { + if ( hHrtf->ModelParams.UseItdModel ) + { + free( hHrtf->ModelParamsITD.elevKSeq_dyn ); + free( hHrtf->ModelParamsITD.azimKSeq_dyn ); + free( hHrtf->ModelParamsITD.W_dyn ); + free( hHrtf->ModelParamsITD.azimBsShape_dyn ); + free( hHrtf->ModelParamsITD.elevBsShape_dyn ); + } + free( hHrtf->ModelParams.elevKSeq_dyn ); + free( hHrtf->ModelParams.azim_start_idx_dyn ); + free( hHrtf->ModelParams.azimDim2_dyn ); + free( hHrtf->ModelParams.azimDim3_dyn ); + free( hHrtf->ModelParams.AlphaL_dyn ); + free( hHrtf->ModelParams.AlphaR_dyn ); + free( hHrtf->ModelParams.azimSegSamples_dyn ); + + free( hHrtf->ModelParams.azimShapeIdx_dyn ); + free( hHrtf->ModelParams.azimShapeSampFactor_dyn ); + free( hHrtf->ModelParams.elevBsShape_dyn ); + + for ( i = 0; i < hHrtf->ModelParams.num_unique_azim_splines; i++ ) + { + free( hHrtf->ModelParams.azimBsShape_dyn[i] ); + free( &hHrtf->ModelParams.azimBsShape_dyn[i] ); + } + + free( (void *) hHrtf->ModelParams.azimBsShape ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ + for ( i = 0; i < hHrtf->ModelParams.elevDim3; i++ ) + { + free( hHrtf->ModelParams.azimKSeq[i] ); + } + free( hHrtf->ModelParams.azimKSeq ); + + free( hHrtf->ModelParams.EL_dyn ); + free( hHrtf->ModelParams.ER_dyn ); + + free( hHrtf->ModelEval.hrfModL ); + free( hHrtf->ModelEval.hrfModR ); + } + + return error; +} + +#endif diff --git a/lib_util/hrtf_file_reader.h b/lib_util/hrtf_file_reader.h index c7b751ad76846a49e13e4597f244f0225419b135..354362e997ebb0894d951c956a1a4729396be37e 100644 --- a/lib_util/hrtf_file_reader.h +++ b/lib_util/hrtf_file_reader.h @@ -73,4 +73,16 @@ ivas_error load_HRTF_binary( const hrtfFileReader *hrtfReader /* i/o: pointer to hrtfFileReader handle */ ); +#ifdef FIX_235 +/*---------------------------------------------------------------------* + * dealloc_HRTF_binary() + * + * Deallocated memory allocated by load_HRTF_binary + *---------------------------------------------------------------------*/ + +ivas_error dealloc_HRTF_binary( + IVAS_DEC_HRTF_HANDLE hHrtf /* i/o: HRTF handle */ +); +#endif + #endif /* IVAS_HRTF_FILE_READER_H */