From 911e9627936fccd116f5502c82a35955acb3b8ec Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Fri, 9 Jan 2026 07:59:15 +0100 Subject: [PATCH 1/8] Change AlphaL/R to Word16 --- lib_com/options.h | 2 +- lib_rend/ivas_objectRenderer_hrFilt_fx.c | 5 +++++ lib_rend/ivas_objectRenderer_mix_fx.c | 27 ++++++++++++++++++++++++ lib_rend/ivas_stat_rend.h | 13 ++++++++++++ lib_util/hrtf_file_reader.c | 26 +++++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/lib_com/options.h b/lib_com/options.h index 1a7b596d5..3a4c3eff0 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -96,7 +96,7 @@ #define FIX_2015_PREMPH_SAT_ALT_PART2 /* VA: Add missing scaling factor to be passed to AVQ_cod() */ #define FIX_2253_CORRECT_GSC_MINIMUM_PIT_SEARCH /* VA: Fix Issue 2253 where the encoder and decoder could get out of sync */ #define NONBE_FIX_1967_SBA_DECODER_MONO_OUT_BIG_DIFFERENCES /* Dolby: Fix basop issue 1967 */ - +#define FIX_2235_TD_RENDERER_WORD16 /* Eri: Use Word16 in TD renderer without converting to Word32 */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index 2a67d7a39..62d9cf9bc 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -357,8 +357,13 @@ static void GenerateFilter_fx( FOR( i = 0; i < p; i++ ) { +#ifdef FIX_2235_TD_RENDERER_WORD16 + temp1 = W_add( temp1, Mpy_32_16_1( modelEval->BM_fx[modelEval->BMEnergiesL[modelEval->UseIndsL[i]].i], model->AlphaL_fx[BM_idx[modelEval->BMEnergiesL[modelEval->UseIndsL[i]].i] + ( model->AlphaN * k )] ) ); // add(model->AlphaL_e, 1) + temp2 = W_add( temp2, Mpy_32_16_1( modelEval->BM_fx[modelEval->BMEnergiesR[modelEval->UseIndsR[i]].i], model->AlphaR_fx[BM_idx[modelEval->BMEnergiesR[modelEval->UseIndsR[i]].i] + ( model->AlphaN * k )] ) ); // add(model->AlphaR_e, 1) +#else temp1 = W_add( temp1, Mpy_32_32( modelEval->BM_fx[modelEval->BMEnergiesL[modelEval->UseIndsL[i]].i], model->AlphaL_fx[BM_idx[modelEval->BMEnergiesL[modelEval->UseIndsL[i]].i] + ( model->AlphaN * k )] ) ); // add(model->AlphaL_e, 1) temp2 = W_add( temp2, Mpy_32_32( modelEval->BM_fx[modelEval->BMEnergiesR[modelEval->UseIndsR[i]].i], model->AlphaR_fx[BM_idx[modelEval->BMEnergiesR[modelEval->UseIndsR[i]].i] + ( model->AlphaN * k )] ) ); // add(model->AlphaR_e, 1) +#endif } tmp_hrfModL_e = W_norm( temp1 ); diff --git a/lib_rend/ivas_objectRenderer_mix_fx.c b/lib_rend/ivas_objectRenderer_mix_fx.c index 28ee13931..5bb7c4925 100644 --- a/lib_rend/ivas_objectRenderer_mix_fx.c +++ b/lib_rend/ivas_objectRenderer_mix_fx.c @@ -504,6 +504,14 @@ static ivas_error DefaultBSplineModel_fx( SWITCH( output_Fs ) { case 48000: +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->AlphaL_fx = (const Word16 *) defaultHRIR_rom_AlphaL48_fx; // Q14 + model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha48_Q_fx; + move16(); + model->AlphaR_fx = (const Word16 *) defaultHRIR_rom_AlphaR48_fx; // Q14 + model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha48_Q_fx; + move16(); +#else model->AlphaL_dyn_fx = (Word32 *) malloc( 60160 * sizeof( Word32 ) ); if ( model->AlphaL_dyn_fx == NULL ) { @@ -524,6 +532,7 @@ static ivas_error DefaultBSplineModel_fx( model->AlphaR_fx = model->AlphaR_dyn_fx; model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha48_Q_fx; move16(); +#endif model->EL_fx = (const Word32 *) defaultHRIR_rom_EL48_fx; // Q28 model->EL_e = Q31 - defaultHRIR_rom_E48_Q_fx; move16(); @@ -539,6 +548,14 @@ static ivas_error DefaultBSplineModel_fx( } BREAK; case 32000: +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->AlphaL_fx = (const Word16 *) defaultHRIR_rom_AlphaL32_fx; // Q14 + model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha32_Q_fx; + move16(); + model->AlphaR_fx = (const Word16 *) defaultHRIR_rom_AlphaR32_fx; // Q14 + model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha32_Q_fx; + move16(); +#else model->AlphaL_dyn_fx = (Word32 *) malloc( 40420 * sizeof( Word32 ) ); if ( model->AlphaL_dyn_fx == NULL ) { @@ -559,6 +576,7 @@ static ivas_error DefaultBSplineModel_fx( model->AlphaR_fx = model->AlphaR_dyn_fx; model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha32_Q_fx; move16(); +#endif model->EL_fx = (const Word32 *) defaultHRIR_rom_EL32_fx; // Q28 model->EL_e = Q31 - defaultHRIR_rom_E32_Q_fx; move16(); @@ -574,6 +592,14 @@ static ivas_error DefaultBSplineModel_fx( } BREAK; case 16000: +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->AlphaL_fx = (const Word16 *) defaultHRIR_rom_AlphaL16_fx; // Q14 + model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha16_Q_fx; + move16(); + model->AlphaR_fx = (const Word16 *) defaultHRIR_rom_AlphaR16_fx; // Q14 + model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha16_Q_fx; + move16(); +#else model->AlphaL_dyn_fx = (Word32 *) malloc( 20210 * sizeof( Word32 ) ); if ( model->AlphaL_dyn_fx == NULL ) { @@ -592,6 +618,7 @@ static ivas_error DefaultBSplineModel_fx( model->AlphaR_fx = model->AlphaR_dyn_fx; model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha16_Q_fx; move16(); +#endif model->EL_fx = (const Word32 *) defaultHRIR_rom_EL16_fx; // Q28 model->EL_e = Q31 - defaultHRIR_rom_E16_Q_fx; move16(); diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index d84a00a1b..4e9d66670 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1056,9 +1056,17 @@ typedef struct const Word32 *elevBsShape_fx; const Word32 **azimBsShape_fx; Word32 **azimKSeq_fx; /* Array, length azimDim3+1 */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 *AlphaL_fx; /* Array, size AlphaN x K */ +#else const Word32 *AlphaL_fx; /* Array, size AlphaN x K */ +#endif Word16 AlphaL_e; +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 *AlphaR_fx; /* Array, size AlphaN x K */ +#else const Word32 *AlphaR_fx; /* Array, size AlphaN x K */ +#endif Word16 AlphaR_e; const Word32 *EL_fx; /* Array, size (AlphaN*HRTF_MODEL_N_SECTIONS) */ Word16 EL_e; @@ -1069,8 +1077,13 @@ typedef struct Word16 iSecFirst[HRTF_MODEL_N_SECTIONS]; /* Indices for start of sections */ Word16 iSecLast[HRTF_MODEL_N_SECTIONS]; /* Indices for end of sections */ /* Pointers for allocation of dynamic memory */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + Word16 *AlphaL_dyn_fx; + Word16 *AlphaR_dyn_fx; +#else Word32 *AlphaL_dyn_fx; Word32 *AlphaR_dyn_fx; +#endif Word32 *EL_dyn_fx; Word32 *ER_dyn_fx; Word32 *elevBsShape_dyn_fx; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index db7d42d7c..83e088625 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -529,6 +529,13 @@ static ivas_error TDREND_LoadBSplineBinary( } fread( &model->AlphaN, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->AlphaL_dyn_fx = (Word16 *) malloc( model->AlphaN * model->K * sizeof( Word16 ) ); + if ( model->AlphaL_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } +#else model->AlphaL_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( model->AlphaN * model->K * sizeof( Word16 ) ); @@ -536,17 +543,30 @@ static ivas_error TDREND_LoadBSplineBinary( { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } +#endif fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf ); model->AlphaL_e = Q15 - factor_Q; // model->AlphaL_dyn_e = 1; /* force to 6 to be corrected */ model->AlphaR_e = model->AlphaL_e; +#ifdef FIX_2235_TD_RENDERER_WORD16 + fread( model->AlphaL_dyn_fx, sizeof( Word16 ), model->AlphaN * model->K, f_hrtf ); +#else fread( v_tmp16, sizeof( Word16 ), model->AlphaN * model->K, f_hrtf ); for ( j = 0; j < model->AlphaN * model->K; j++ ) { model->AlphaL_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q30 - factor_Q ); } +#endif +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->AlphaR_dyn_fx = (Word16 *) malloc( model->AlphaN * model->K * sizeof( Word16 ) ); + if ( model->AlphaR_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( model->AlphaR_dyn_fx, sizeof( Word16 ), model->AlphaN * model->K, f_hrtf ); +#else model->AlphaR_dyn_fx = (Word32 *) malloc( model->AlphaN * model->K * sizeof( Word32 ) ); if ( model->AlphaR_dyn_fx == NULL ) { @@ -560,6 +580,7 @@ static ivas_error TDREND_LoadBSplineBinary( } free( v_tmp16 ); +#endif /* azimuth */ fread( &model->num_unique_azim_splines, sizeof( Word16 ), 1, f_hrtf ); @@ -660,8 +681,13 @@ static ivas_error TDREND_LoadBSplineBinary( fread( (Word32 *) model->ER_dyn_fx, sizeof( Word32 ), model->AlphaN * HRTF_MODEL_N_SECTIONS, f_hrtf ); /* Set const pointers */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->AlphaL_fx = (const Word16 *) model->AlphaL_dyn_fx; + model->AlphaR_fx = (const Word16 *) model->AlphaR_dyn_fx; +#else model->AlphaL_fx = (const Word32 *) model->AlphaL_dyn_fx; model->AlphaR_fx = (const Word32 *) model->AlphaR_dyn_fx; +#endif model->EL_fx = (const Word32 *) model->EL_dyn_fx; model->ER_fx = (const Word32 *) model->ER_dyn_fx; model->elevBsLen = (const Word16 *) model->elevBsLen_dyn; -- GitLab From 9f88d2199ced55a0ad7a82c298641441443a2ae8 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 20 Jan 2026 10:26:28 +0100 Subject: [PATCH 2/8] Change to Word16 for knot sequence parameters --- lib_rend/ivas_objectRenderer_hrFilt_fx.c | 61 +++++++++++++++++++++--- lib_rend/ivas_objectRenderer_mix_fx.c | 19 ++++++++ lib_rend/ivas_stat_rend.h | 35 ++++++++++---- lib_util/hrtf_file_reader.c | 40 ++++++++++++++++ 4 files changed, 141 insertions(+), 14 deletions(-) diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index 62d9cf9bc..0ca3c4992 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -45,7 +45,11 @@ *---------------------------------------------------------------------*/ static void getPeriodicBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *AzIdx, const Word16 NumBFs, const Word32 t_fx, Word16 *num_az_idx, const Word32 knot_interval_fx, const Word32 azimKSeq_0_fx, const Word16 azimSegSamples, const Word32 *azimBsShape_fx, const Word16 subSampFactor ); +#ifdef FIX_2235_TD_RENDERER_WORD16 +static void getStandardBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *NzIdx, Word16 *num_idx, const Word16 NumBFs, const Word32 t_fx, const Word16 *KSeq_fx, const Word16 KSeq_Q_fx, const Word16 SegSamples, const Word16 *BsLen, const Word16 *BsStart, const Word32 *BsShape_fx ); +#else static void getStandardBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *NzIdx, Word16 *num_idx, const Word16 NumBFs, const Word32 t_fx, const Word32 *KSeq_fx, const Word16 SegSamples, const Word16 *BsLen, const Word16 *BsStart, const Word32 *BsShape_fx ); +#endif static void GenerateFilter_fx( const Word32 elev, Word32 azim, ModelParams_t *model, ModelEval_t *modelEval ); static void GenerateITD_fx( const Word32 elev, Word32 azim, ModelParamsITD_t *model, ModelEval_t *modelEval ); static void SkipSmallest_ValueIndex_fx( Word16 *use_inds, const ValueIndex_t *VI, const Word16 N, const Word16 n_smallest ); @@ -215,8 +219,13 @@ static void GenerateFilter_fx( Word16 BMEnergiesR_e, BMEnergiesL_e; Word16 tmp_hrfModR_e, tmp_hrfModL_e; +#ifdef FIX_2235_TD_RENDERER_WORD16 + getStandardBSplineSampVec_fx( modelEval->elevBfVec_fx, EvIdx, &num_ev_idx, model->elevDim3, elev, model->elevKSeq_fx, model->elevKSeq_Q_fx, + model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx ); +#else getStandardBSplineSampVec_fx( modelEval->elevBfVec_fx, EvIdx, &num_ev_idx, model->elevDim3, elev, model->elevKSeq_fx, model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx ); +#endif FOR( p = 0; p < num_ev_idx; p++ ) { @@ -450,8 +459,13 @@ static void GenerateITD_fx( IF( NE_32( L_abs( elev_fx ), DEG_90_IN_Q22 ) ) { +#ifdef FIX_2235_TD_RENDERER_WORD16 + getStandardBSplineSampVec_fx( modelEval->elevBfVecITD_fx, EvIdx, &num_ev_idx, model->elevDim3, elev_fx, model->elevKSeq_fx, model->elevKSeq_Q_fx, + model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx ); +#else getStandardBSplineSampVec_fx( modelEval->elevBfVecITD_fx, EvIdx, &num_ev_idx, model->elevDim3, elev_fx, model->elevKSeq_fx, model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx ); +#endif azim_itd_fx = azim_fx; move32(); @@ -460,8 +474,13 @@ static void GenerateITD_fx( /* Flip spline functions around 180 deg */ azim_itd_fx = L_sub( DEG_360_IN_Q22, azim_fx ); // Q22 } +#ifdef FIX_2235_TD_RENDERER_WORD16 + getStandardBSplineSampVec_fx( modelEval->azimBfVecITD_fx, AzIdx, &num_az_idx, shr( add( model->azimDim3, 1 ), 1 ), azim_itd_fx, model->azimKSeq_fx, model->azimKSeq_Q_fx, + model->azimSegSamples, model->azimBsLen, model->azimBsStart, model->azimBsShape_fx ); +#else getStandardBSplineSampVec_fx( modelEval->azimBfVecITD_fx, AzIdx, &num_az_idx, shr( add( model->azimDim3, 1 ), 1 ), azim_itd_fx, model->azimKSeq_fx, model->azimSegSamples, model->azimBsLen, model->azimBsStart, model->azimBsShape_fx ); +#endif IF( GT_32( azim_fx, DEG_180_IN_Q22 ) ) { /* Flip spline functions around 180 deg */ @@ -497,7 +516,11 @@ static void GenerateITD_fx( /* Compute BM_ITD */ elev_offset = 0; move16(); +#ifdef FIX_2235_TD_RENDERER_WORD16 + if ( EQ_16( model->elevKSeq_fx[0], shl( -90, model->elevKSeq_Q_fx ) ) ) +#else if ( EQ_32( model->elevKSeq_fx[0], -DEG_90_IN_Q22 ) ) +#endif { elev_offset = sub( 1, model->azimDim3 ); } @@ -509,7 +532,11 @@ static void GenerateITD_fx( test(); test(); test(); +#ifdef FIX_2235_TD_RENDERER_WORD16 + IF( EvIdx[p] == 0 && EQ_16( model->elevKSeq_fx[EvIdx[p]], shl( -90, model->elevKSeq_Q_fx ) ) ) +#else IF( EvIdx[p] == 0 && EQ_32( model->elevKSeq_fx[EvIdx[p]], -DEG_90_IN_Q22 ) ) +#endif { modelEval->BM_ITD_fx[qp] = modelEval->elevBfVecITD_fx[p]; // Q30 move32(); @@ -517,7 +544,11 @@ static void GenerateITD_fx( move16(); qp = add( qp, 1 ); } +#ifdef FIX_2235_TD_RENDERER_WORD16 + ELSE IF( EQ_16( EvIdx[p], sub( model->elevDim3, 1 ) ) && EQ_16( model->elevKSeq_fx[sub( EvIdx[p], 2 )], shl( 90, model->elevKSeq_Q_fx ) ) ) +#else ELSE IF( EQ_16( EvIdx[p], sub( model->elevDim3, 1 ) ) && EQ_32( model->elevKSeq_fx[sub( EvIdx[p], 2 )], DEG_90_IN_Q22 ) ) +#endif { /* NB: -2 in if() condition above as number of knot points is numBF-2 */ modelEval->BM_ITD_fx[qp] = modelEval->elevBfVecITD_fx[p]; // Q30 @@ -542,7 +573,11 @@ static void GenerateITD_fx( /* Compute ITD */ AlphaN = add( imult1616( model->elevDim3, model->azimDim3 ), elev_offset ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + if ( EQ_16( model->elevKSeq_fx[sub( model->elevDim3, 3 )], shl( 90, model->elevKSeq_Q_fx ) ) ) /* Constant azimuth basis function */ +#else if ( EQ_32( model->elevKSeq_fx[sub( model->elevDim3, 3 )], DEG_90_IN_Q22 ) ) /* Constant azimuth basis function */ +#endif { AlphaN = sub( AlphaN, sub( model->azimDim3, 1 ) ); } @@ -667,12 +702,17 @@ static void getPeriodicBSplineSampVec_fx( --------------------------------------------------------------------*/ static void getStandardBSplineSampVec_fx( - Word32 *BfVec_fx, /* o : values for non-zero basis functions Q30 */ - Word16 *NzIdx, /* o : indices of non-zero basis functions */ - Word16 *num_idx, /* i/o: number of non-zero indices */ - const Word16 NumBFs, /* i : the number of basis functions = third index of Bf */ - const Word32 t_fx, /* i : estimation point Q22 */ - const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ + Word32 *BfVec_fx, /* o : values for non-zero basis functions Q30 */ + Word16 *NzIdx, /* o : indices of non-zero basis functions */ + Word16 *num_idx, /* i/o: number of non-zero indices */ + const Word16 NumBFs, /* i : the number of basis functions = third index of Bf */ + const Word32 t_fx, /* i : estimation point Q22 */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 *KSeq_fx, /* i : knot sequence including multiplicities Q KSeq_Q_fx */ + const Word16 KSeq_Q_fx, /* i : Q-value of knot sequence */ +#else + const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ +#endif const Word16 SegSamples, /* i : samples per segment */ const Word16 *BsLen, /* i : lengths of basis shapes */ const Word16 *BsStart, /* i : start of basis shapes */ @@ -686,13 +726,22 @@ static void getStandardBSplineSampVec_fx( Word32 tmp32; /* assuming triple knot at the first knot */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + tmp32 = L_shl( L_sub( L_deposit_l( KSeq_fx[NumBFs - 3] ), L_deposit_l( KSeq_fx[0] ) ), sub( 22, KSeq_Q_fx ) ); /* Q22 */ + knot_interval_fx = L_deposit_h( BASOP_Util_Divide3216_Scale( tmp32, sub( NumBFs, 3 ), &tmp_e1 ) ); +#else knot_interval_fx = L_deposit_h( BASOP_Util_Divide3216_Scale( L_sub( KSeq_fx[NumBFs - 3], KSeq_fx[0] ), sub( NumBFs, 3 ), &tmp_e1 ) ); +#endif tmp_e1 = add( tmp_e1, 9 - 15 ); /* index of closest sample point */ tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( knot_interval_fx, SegSamples, &tmp_e2 ) ); tmp_e2 = add( tmp_e2, sub( tmp_e1, 15 ) ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( L_sub( t_fx, L_shl( L_deposit_l( KSeq_fx[0] ), 22 - KSeq_Q_fx ) ), tmp32, &tmp_e3 ) ); +#else tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( L_sub( t_fx, KSeq_fx[0] ), tmp32, &tmp_e3 ) ); +#endif tmp_e3 = add( tmp_e3, sub( 9, tmp_e2 ) ); tmp32 = L_shr( tmp32, sub( 9, tmp_e3 ) ); // Q22 (assuming tmp32 will be in range of Q22) d0 = extract_l( round_hrFilt_fx( tmp32, 22 ) ); diff --git a/lib_rend/ivas_objectRenderer_mix_fx.c b/lib_rend/ivas_objectRenderer_mix_fx.c index 5bb7c4925..ff85a5e26 100644 --- a/lib_rend/ivas_objectRenderer_mix_fx.c +++ b/lib_rend/ivas_objectRenderer_mix_fx.c @@ -179,15 +179,19 @@ void TDREND_MIX_Dealloc_fx( { IF( hBinRendererTd->HrFiltSet_p->ModelParams.UseItdModel ) { +#ifndef FIX_2235_TD_RENDERER_WORD16 free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.elevKSeq_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.azimKSeq_dyn_fx ); +#endif free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.W_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.azimBsShape_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.elevBsShape_dyn_fx ); } +#ifndef FIX_2235_TD_RENDERER_WORD16 free( hBinRendererTd->HrFiltSet_p->ModelParams.elevKSeq_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParams.AlphaL_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParams.AlphaR_dyn_fx ); +#endif free( hBinRendererTd->HrFiltSet_p->ModelParams.elevBsShape_dyn_fx ); } @@ -438,6 +442,10 @@ static ivas_error DefaultBSplineModel_fx( model->azimShapeIdx = defaultHRIR_rom_azimShapeIdx; // Q0 model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; // Q0 +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->elevKSeq_fx = (const Word16 *) defaultHRIR_rom_elevKSeq_fx; + model->elevKSeq_Q_fx = defaultHRIR_rom_elevKSeq_Q_fx; +#else model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); IF( model->elevKSeq_dyn_fx == NULL ) { @@ -445,6 +453,7 @@ static ivas_error DefaultBSplineModel_fx( } Copy_Scale_sig_16_32_r( defaultHRIR_rom_elevKSeq_fx, model->elevKSeq_dyn_fx, ( model->elevDim3 - 2 ), Q22 - defaultHRIR_rom_elevKSeq_Q_fx ); // Q22 model->elevKSeq_fx = model->elevKSeq_dyn_fx; +#endif model->elevBsShape_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_elevBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); IF( model->elevBsShape_dyn_fx == NULL ) @@ -648,6 +657,10 @@ static ivas_error DefaultBSplineModel_fx( modelITD->elevBsLen = defaultHRIR_rom_ITD_elevBsLen; modelITD->elevBsStart = defaultHRIR_rom_ITD_elevBsStart; +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->elevKSeq_fx = (const Word16 *) defaultHRIR_rom_ITD_elevKSeq_fx; + modelITD->elevKSeq_Q_fx = defaultHRIR_rom_ITD_elevKSeq_Q_fx; +#else modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_elevKSeq_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); IF( modelITD->elevKSeq_dyn_fx == NULL ) { @@ -656,10 +669,15 @@ static ivas_error DefaultBSplineModel_fx( Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_elevKSeq_fx, modelITD->elevKSeq_dyn_fx, sizeof( defaultHRIR_rom_ITD_elevKSeq_fx ) / sizeof( Word16 ), Q22 - defaultHRIR_rom_ITD_elevKSeq_Q_fx ); // Q22 modelITD->elevKSeq_fx = modelITD->elevKSeq_dyn_fx; +#endif modelITD->azimBsLen = defaultHRIR_rom_ITD_azimBsLen; modelITD->azimBsStart = defaultHRIR_rom_ITD_azimBsStart; +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->azimKSeq_fx = (const Word16 *) defaultHRIR_rom_ITD_azimKSeq_fx; + modelITD->azimKSeq_Q_fx = defaultHRIR_rom_ITD_azimKSeq_Q_fx; +#else modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ IF( modelITD->azimKSeq_dyn_fx == NULL ) { @@ -667,6 +685,7 @@ static ivas_error DefaultBSplineModel_fx( } Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_azimKSeq_fx, modelITD->azimKSeq_dyn_fx, ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ), Q22 - defaultHRIR_rom_ITD_azimKSeq_Q_fx ); // Q22 modelITD->azimKSeq_fx = modelITD->azimKSeq_dyn_fx; +#endif modelITD->W_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_W_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ IF( modelITD->W_dyn_fx == NULL ) { diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 4e9d66670..b7a12196a 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1052,19 +1052,22 @@ typedef struct const Word16 *azimShapeIdx; const Word16 *azimShapeSampFactor; - const Word32 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ + Word16 elevKSeq_Q_fx; /* Q-value of elevKSeq_fx */ const Word32 *elevBsShape_fx; const Word32 **azimBsShape_fx; Word32 **azimKSeq_fx; /* Array, length azimDim3+1 */ -#ifdef FIX_2235_TD_RENDERER_WORD16 const Word16 *AlphaL_fx; /* Array, size AlphaN x K */ -#else - const Word32 *AlphaL_fx; /* Array, size AlphaN x K */ -#endif Word16 AlphaL_e; -#ifdef FIX_2235_TD_RENDERER_WORD16 const Word16 *AlphaR_fx; /* Array, size AlphaN x K */ #else + const Word32 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ + const Word32 *elevBsShape_fx; + const Word32 **azimBsShape_fx; + Word32 **azimKSeq_fx; /* Array, length azimDim3+1 */ + const Word32 *AlphaL_fx; /* Array, size AlphaN x K */ + Word16 AlphaL_e; const Word32 *AlphaR_fx; /* Array, size AlphaN x K */ #endif Word16 AlphaR_e; @@ -1087,7 +1090,11 @@ typedef struct Word32 *EL_dyn_fx; Word32 *ER_dyn_fx; Word32 *elevBsShape_dyn_fx; +#ifdef FIX_2235_TD_RENDERER_WORD16 + Word16 *elevKSeq_dyn_fx; +#else Word32 *elevKSeq_dyn_fx; +#endif Word16 *elevBsLen_dyn; Word16 *elevBsStart_dyn; Word16 *azimDim3_dyn; @@ -1110,17 +1117,29 @@ typedef struct const Word16 *elevBsLen; const Word16 *elevBsStart; Word16 elevSegSamples; - Word16 resamp_factor_fx; /*Q14*/ + Word16 resamp_factor_fx; /*Q14*/ +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 *elevKSeq_fx; /* Array, length elevDim3-2 */ + Word16 elevKSeq_Q_fx; /* Q-value of elevKSeq_fx */ + const Word16 *azimKSeq_fx; /* Array, length azimDim3-2 */ + Word16 azimKSeq_Q_fx; /* Q-value of azimKSeq_fx */ +#else const Word32 *elevKSeq_fx; /* Array, length elevDim3-2 */ const Word32 *azimKSeq_fx; /* Array, length azimDim3-2 */ - const Word32 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ +#endif + const Word32 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ Word16 W_e; const Word32 *azimBsShape_fx; const Word32 *elevBsShape_fx; /* Pointers for allocation of dynamic memory */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + Word16 *elevKSeq_dyn_fx; + Word16 *azimKSeq_dyn_fx; +#else Word32 *elevKSeq_dyn_fx; Word32 *azimKSeq_dyn_fx; +#endif Word32 *W_dyn_fx; Word32 *azimBsShape_dyn_fx; Word32 *elevBsShape_dyn_fx; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 83e088625..b1b7f0c2a 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -293,6 +293,15 @@ static ivas_error TDREND_LoadBSplineBinaryITD( } fread( &modelITD->elevDim3, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->elevKSeq_dyn_fx = (Word16 *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( Word16 ) ); + if ( modelITD->elevKSeq_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &modelITD->elevKSeq_Q_fx, 1, sizeof( Word16 ), f_hrtf ); + fread( modelITD->elevKSeq_dyn_fx, sizeof( Word16 ), modelITD->elevDim3 - 2, f_hrtf ); +#else modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( ( modelITD->elevDim3 - 2 ) * sizeof( Word16 ) ); if ( modelITD->elevKSeq_dyn_fx == NULL || v_tmp16 == NULL ) @@ -306,8 +315,18 @@ static ivas_error TDREND_LoadBSplineBinaryITD( modelITD->elevKSeq_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q22 - factor_Q ); } free( v_tmp16 ); +#endif fread( &modelITD->azimDim3, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->azimKSeq_dyn_fx = (Word16 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word16 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ + if ( modelITD->azimKSeq_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &modelITD->azimKSeq_Q_fx, 1, sizeof( Word16 ), f_hrtf ); + fread( modelITD->azimKSeq_dyn_fx, sizeof( Word16 ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf ); +#else modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ v_tmp16 = (Word16 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word16 ) ); if ( modelITD->azimKSeq_dyn_fx == NULL || v_tmp16 == NULL ) @@ -321,6 +340,7 @@ static ivas_error TDREND_LoadBSplineBinaryITD( modelITD->azimKSeq_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q22 - factor_Q ); } free( v_tmp16 ); +#endif fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); modelITD->W_dyn_fx = (Word32 *) malloc( tmp * sizeof( Word32 ) ); @@ -410,8 +430,13 @@ static ivas_error TDREND_LoadBSplineBinaryITD( free( v_tmp16 ); fread( &modelITD->elevSegSamples, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->elevKSeq_fx = (const Word16 *) modelITD->elevKSeq_dyn_fx; + modelITD->azimKSeq_fx = (const Word16 *) modelITD->azimKSeq_dyn_fx; +#else modelITD->elevKSeq_fx = (const Word32 *) modelITD->elevKSeq_dyn_fx; modelITD->azimKSeq_fx = (const Word32 *) modelITD->azimKSeq_dyn_fx; +#endif modelITD->W_fx = (const Word32 *) modelITD->W_dyn_fx; modelITD->azimBsShape_fx = (const Word32 *) modelITD->azimBsShape_dyn_fx; modelITD->elevBsShape_fx = (const Word32 *) modelITD->elevBsShape_dyn_fx; @@ -486,6 +511,15 @@ static ivas_error TDREND_LoadBSplineBinary( fread( &model->K, sizeof( Word16 ), 1, f_hrtf ); fread( &model->elevDim3, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->elevKSeq_dyn_fx = (Word16 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word16 ) ); + if ( model->elevKSeq_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &model->elevKSeq_Q_fx, 1, sizeof( Word16 ), f_hrtf ); + fread( model->elevKSeq_dyn_fx, sizeof( Word16 ), model->elevDim3 - 2, f_hrtf ); +#else model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word16 ) ); @@ -500,6 +534,8 @@ static ivas_error TDREND_LoadBSplineBinary( model->elevKSeq_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q22 - factor_Q ); } free( v_tmp16 ); +#endif + model->azimDim3_dyn = (Word16 *) malloc( model->elevDim3 * sizeof( Word16 ) ); model->azim_start_idx_dyn = (Word16 *) malloc( model->elevDim3 * sizeof( Word16 ) ); model->azimKSeq_fx = (Word32 **) malloc( model->elevDim3 * sizeof( Word32 * ) ); @@ -693,7 +729,11 @@ static ivas_error TDREND_LoadBSplineBinary( model->elevBsLen = (const Word16 *) model->elevBsLen_dyn; model->elevBsStart = (const Word16 *) model->elevBsStart_dyn; model->elevBsShape_fx = (const Word32 *) model->elevBsShape_dyn_fx; +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->elevKSeq_fx = (const Word16 *) model->elevKSeq_dyn_fx; +#else model->elevKSeq_fx = (const Word32 *) model->elevKSeq_dyn_fx; +#endif model->azimDim3 = (const Word16 *) model->azimDim3_dyn; model->azim_start_idx = (const Word16 *) model->azim_start_idx_dyn; model->azimSegSamples = (const Word16 *) model->azimSegSamples_dyn; -- GitLab From 8442c51cb4536620f2c10612cbcfce9a73f7bbdd Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 21 Jan 2026 16:52:21 +0100 Subject: [PATCH 3/8] Add B-spline shape vectors to Word16 memory --- lib_rend/ivas_hrtf_fx.c | 42 +++++++++++ lib_rend/ivas_objectRenderer_hrFilt_fx.c | 61 +++++++++++++--- lib_rend/ivas_objectRenderer_mix_fx.c | 87 +++++++++++++++++++---- lib_rend/ivas_prot_rend_fx.h | 14 ++++ lib_rend/ivas_rom_TdBinauralRenderer.h | 3 + lib_rend/ivas_rom_TdBinauralRenderer_fx.c | 3 + lib_rend/ivas_stat_rend.h | 30 ++++++-- lib_util/hrtf_file_reader.c | 79 +++++++++++++++++++- 8 files changed, 289 insertions(+), 30 deletions(-) diff --git a/lib_rend/ivas_hrtf_fx.c b/lib_rend/ivas_hrtf_fx.c index 537323af5..c597514f1 100644 --- a/lib_rend/ivas_hrtf_fx.c +++ b/lib_rend/ivas_hrtf_fx.c @@ -255,6 +255,48 @@ ivas_error ivas_HRTF_binary_open_buffers_int32_ptr( return IVAS_ERR_OK; } +#ifdef FIX_2235_TD_RENDERER_WORD16 +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_int16_ptr_const() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_int16_ptr_const( + const Word16 ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (const Word16 **) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} + +/*-----------------------------------------------------------------------* + * ivas_HRTF_binary_open_buffers_int16_ptr() + * + * Allocate buffer with dynamic length for HRTF binary Crend handle + *-----------------------------------------------------------------------*/ +ivas_error ivas_HRTF_binary_open_buffers_int16_ptr( + Word16 ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +) +{ + *buffer = (Word16 **) malloc( mem_size ); + + if ( *buffer == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" ); + } + + return IVAS_ERR_OK; +} +#endif + /*-----------------------------------------------------------------------* * ivas_HRTF_binary_open_buffers_int32_ptr_const() * diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index 9adafa66c..f6d041740 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -44,10 +44,12 @@ * Local function prototypes *---------------------------------------------------------------------*/ -static void getPeriodicBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *AzIdx, const Word16 NumBFs, const Word32 t_fx, Word16 *num_az_idx, const Word32 knot_interval_fx, const Word32 azimKSeq_0_fx, const Word16 azimSegSamples, const Word32 *azimBsShape_fx, const Word16 subSampFactor ); + #ifdef FIX_2235_TD_RENDERER_WORD16 -static void getStandardBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *NzIdx, Word16 *num_idx, const Word16 NumBFs, const Word32 t_fx, const Word16 *KSeq_fx, const Word16 KSeq_Q_fx, const Word16 SegSamples, const Word16 *BsLen, const Word16 *BsStart, const Word32 *BsShape_fx ); +static void getPeriodicBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *AzIdx, const Word16 NumBFs, const Word32 t_fx, Word16 *num_az_idx, const Word32 knot_interval_fx, const Word16 azimKSeq_0_fx, const Word16 azimKSeq_Q_fx, const Word16 azimSegSamples, const Word16 *azimBsShape_fx, const Word16 azimBsShape_Q_fx, const Word16 subSampFactor ); +static void getStandardBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *NzIdx, Word16 *num_idx, const Word16 NumBFs, const Word32 t_fx, const Word16 *KSeq_fx, const Word16 KSeq_Q_fx, const Word16 SegSamples, const Word16 *BsLen, const Word16 *BsStart, const Word16 *BsShape_fx, Word16 BsShape_Q_fx ); #else +static void getPeriodicBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *AzIdx, const Word16 NumBFs, const Word32 t_fx, Word16 *num_az_idx, const Word32 knot_interval_fx, const Word32 azimKSeq_0_fx, const Word16 azimSegSamples, const Word32 *azimBsShape_fx, const Word16 subSampFactor ); static void getStandardBSplineSampVec_fx( Word32 *BfVec_fx, Word16 *NzIdx, Word16 *num_idx, const Word16 NumBFs, const Word32 t_fx, const Word32 *KSeq_fx, const Word16 SegSamples, const Word16 *BsLen, const Word16 *BsStart, const Word32 *BsShape_fx ); #endif static void GenerateFilter_fx( const Word32 elev, Word32 azim, ModelParams_t *model, ModelEval_t *modelEval ); @@ -221,7 +223,7 @@ static void GenerateFilter_fx( #ifdef FIX_2235_TD_RENDERER_WORD16 getStandardBSplineSampVec_fx( modelEval->elevBfVec_fx, EvIdx, &num_ev_idx, model->elevDim3, elev, model->elevKSeq_fx, model->elevKSeq_Q_fx, - model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx ); + model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx, model->elevBsShape_Q_fx ); #else getStandardBSplineSampVec_fx( modelEval->elevBfVec_fx, EvIdx, &num_ev_idx, model->elevDim3, elev, model->elevKSeq_fx, model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx ); @@ -255,13 +257,24 @@ static void GenerateFilter_fx( k = EvIdx[p]; move16(); +#ifdef FIX_2235_TD_RENDERER_WORD16 + knot_interval = L_deposit_h( BASOP_Util_Divide3216_Scale( L_sub( L_deposit_l( model->azimKSeq_fx[k][model->azimDim3[k]] ), L_deposit_l( model->azimKSeq_fx[k][0] ) ), model->azimDim3[k], &tmp_e ) ); + tmp_e = add( tmp_e, 16 + 9 - 15 ); +#else knot_interval = L_deposit_h( BASOP_Util_Divide3216_Scale( L_sub( model->azimKSeq_fx[k][model->azimDim3[k]], model->azimKSeq_fx[k][0] ), model->azimDim3[k], &tmp_e ) ); tmp_e = add( tmp_e, 9 - 15 ); +#endif knot_interval = L_shr( knot_interval, sub( 9, tmp_e ) ); // variable Q to Q22 +#ifdef FIX_2235_TD_RENDERER_WORD16 + getPeriodicBSplineSampVec_fx( modelEval->azimBfVec_fx[p], AzIdx[p], model->azimDim3[k], azim, &num_az_idx[p], + knot_interval, model->azimKSeq_fx[k][0], model->azimKSeq_Q_fx[k], model->azimSegSamples[model->azimShapeIdx[k]], + model->azimBsShape_fx[model->azimShapeIdx[k]], model->azimBsShape_Q_fx[model->azimShapeIdx[k]], model->azimShapeSampFactor[k] ); +#else getPeriodicBSplineSampVec_fx( modelEval->azimBfVec_fx[p], AzIdx[p], model->azimDim3[k], azim, &num_az_idx[p], knot_interval, model->azimKSeq_fx[k][0], model->azimSegSamples[model->azimShapeIdx[k]], model->azimBsShape_fx[model->azimShapeIdx[k]], model->azimShapeSampFactor[k] ); +#endif } } @@ -461,7 +474,7 @@ static void GenerateITD_fx( { #ifdef FIX_2235_TD_RENDERER_WORD16 getStandardBSplineSampVec_fx( modelEval->elevBfVecITD_fx, EvIdx, &num_ev_idx, model->elevDim3, elev_fx, model->elevKSeq_fx, model->elevKSeq_Q_fx, - model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx ); + model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx, model->elevBsShape_Q_fx ); #else getStandardBSplineSampVec_fx( modelEval->elevBfVecITD_fx, EvIdx, &num_ev_idx, model->elevDim3, elev_fx, model->elevKSeq_fx, model->elevSegSamples, model->elevBsLen, model->elevBsStart, model->elevBsShape_fx ); @@ -476,7 +489,7 @@ static void GenerateITD_fx( } #ifdef FIX_2235_TD_RENDERER_WORD16 getStandardBSplineSampVec_fx( modelEval->azimBfVecITD_fx, AzIdx, &num_az_idx, shr( add( model->azimDim3, 1 ), 1 ), azim_itd_fx, model->azimKSeq_fx, model->azimKSeq_Q_fx, - model->azimSegSamples, model->azimBsLen, model->azimBsStart, model->azimBsShape_fx ); + model->azimSegSamples, model->azimBsLen, model->azimBsStart, model->azimBsShape_fx, model->azimBsShape_Q_fx ); #else getStandardBSplineSampVec_fx( modelEval->azimBfVecITD_fx, AzIdx, &num_az_idx, shr( add( model->azimDim3, 1 ), 1 ), azim_itd_fx, model->azimKSeq_fx, model->azimSegSamples, model->azimBsLen, model->azimBsStart, model->azimBsShape_fx ); @@ -631,10 +644,20 @@ static void getPeriodicBSplineSampVec_fx( const Word32 t_fx, /* i : azimuth Q22 */ Word16 *num_az_idx, /* o : Number of azimuth indices */ const Word32 knot_interval_fx, /* i : The knot interval Q22 */ - const Word32 azimKSeq_0_fx, /* i : Knot sequence Q22 */ - const Word16 azimSegSamples, /* i : Samples per segment */ - const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ - const Word16 subSampFactor /* i : Subsampling factor */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 azimKSeq_0_fx, /* i : Knot sequence Q azimKSeq_Q_fx*/ + const Word16 azimKSeq_Q_fx, /* i : Q-value of azimKSeq_0_fx */ +#else + const Word32 azimKSeq_0_fx, /* i : Knot sequence Q22 */ +#endif + const Word16 azimSegSamples, /* i : Samples per segment */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 *azimBsShape_fx, /* i : Basis shape Q azimBsShape_Q_fx */ + const Word16 azimBsShape_Q_fx, /* i : Q-value of azimBsShape_fx */ +#else + const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ +#endif + const Word16 subSampFactor /* i : Subsampling factor */ ) { Word16 i, nI, d0, d; @@ -659,7 +682,11 @@ static void getPeriodicBSplineSampVec_fx( { tmp32 = L_deposit_h( BASOP_Util_Divide3216_Scale( knot_interval_fx, SegSamples, &tmp_e1 ) ); tmp_e1 = add( tmp_e1, 9 - 15 ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( L_sub( t_fx, L_shl( L_deposit_l( azimKSeq_0_fx ), 22 - azimKSeq_Q_fx ) ), tmp32, &tmp_e2 ) ); +#else tmp32 = L_deposit_h( BASOP_Util_Divide3232_Scale( L_sub( t_fx, azimKSeq_0_fx ), tmp32, &tmp_e2 ) ); +#endif tmp_e2 = add( tmp_e2, sub( 9, tmp_e1 ) ); tmp32 = L_shr( tmp32, sub( 9, tmp_e2 ) ); // Q22 (assuming tmp32 will be in range of Q22) d0 = extract_l( round_hrFilt_fx( tmp32, Q22 ) ); @@ -686,8 +713,13 @@ static void getPeriodicBSplineSampVec_fx( { d = sub( d0, imult1616( ( sub( add( i, nI ), 1 ) ), SegSamples ) ); /* offset of knot_interval */ d = sub( d0, imult1616( sub( add( i, nI ), 1 ), SegSamples ) ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + BfVec_fx[i] = L_shl( L_deposit_l( azimBsShape_fx[i_mult( abs_s( d ), subSampFactor )] ), 30 - azimBsShape_Q_fx ); +#else BfVec_fx[i] = azimBsShape_fx[i_mult( abs_s( d ), subSampFactor )]; +#endif move32(); + AzIdx[i] = add( nI, i ) % NumBFs; move16(); } @@ -711,12 +743,17 @@ static void getStandardBSplineSampVec_fx( const Word16 *KSeq_fx, /* i : knot sequence including multiplicities Q KSeq_Q_fx */ const Word16 KSeq_Q_fx, /* i : Q-value of knot sequence */ #else - const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ + const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ #endif const Word16 SegSamples, /* i : samples per segment */ const Word16 *BsLen, /* i : lengths of basis shapes */ const Word16 *BsStart, /* i : start of basis shapes */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 *BsShape_fx, /* i : basis shapes Q BsShape_Q_fx */ + Word16 BsShape_Q_fx /* i : Q-value of basis shapes */ +#else const Word32 *BsShape_fx /* i : basis shapes Q30 */ +#endif ) { Word16 i, nI; @@ -776,8 +813,12 @@ static void getStandardBSplineSampVec_fx( { d = sub( shl( sub( BsLen[shape_idx], 1 ), 1 ), d ); } +#ifdef FIX_2235_TD_RENDERER_WORD16 + BfVec_fx[i] = L_shl( L_deposit_l( BsShape_fx[add( BsStart[shape_idx], abs_s( d ) )] ), 30 - BsShape_Q_fx ); /* Q30 */ +#else BfVec_fx[i] = BsShape_fx[add( BsStart[shape_idx], abs_s( d ) )]; /*TT, verify if abs is needed */ move32(); +#endif NzIdx[i] = add( nI, i ); move16(); } diff --git a/lib_rend/ivas_objectRenderer_mix_fx.c b/lib_rend/ivas_objectRenderer_mix_fx.c index 4c700be6c..a129352ed 100644 --- a/lib_rend/ivas_objectRenderer_mix_fx.c +++ b/lib_rend/ivas_objectRenderer_mix_fx.c @@ -431,6 +431,10 @@ static ivas_error DefaultBSplineModel_fx( model->elevKSeq_fx = model->elevKSeq_dyn_fx; #endif +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->elevBsShape_fx = defaultHRIR_rom_elevBsShape_fx; + model->elevBsShape_Q_fx = defaultHRIR_rom_elevBsShape_Q_fx; +#else model->elevBsShape_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_elevBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); IF( model->elevBsShape_dyn_fx == NULL ) { @@ -438,16 +442,29 @@ static ivas_error DefaultBSplineModel_fx( } Copy_Scale_sig_16_32_r( defaultHRIR_rom_elevBsShape_fx, model->elevBsShape_dyn_fx, sizeof( defaultHRIR_rom_elevBsShape_fx ) / sizeof( Word16 ), Q30 - defaultHRIR_rom_elevBsShape_Q_fx ); // Q30 model->elevBsShape_fx = model->elevBsShape_dyn_fx; +#endif +#ifdef FIX_2235_TD_RENDERER_WORD16 + IF( ( model->azimBsShape_fx = (const Word16 **) malloc( model->num_unique_azim_splines * sizeof( Word16 * ) ) ) == NULL || ( model->azimBsShape_Q_fx = (Word16 *) malloc( model->num_unique_azim_splines * sizeof( Word16 ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); + } + model->azimBsShape_dyn_fx = (Word16 **) malloc( sizeof( Word16 * ) ); +#else IF( ( model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } model->azimBsShape_dyn_fx = (Word32 **) malloc( sizeof( Word32 * ) ); +#endif IF( model->azimBsShape_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->azimBsShape_fx[0] = defaultHRIR_rom_azimBsShape_fx; + model->azimBsShape_Q_fx[0] = defaultHRIR_rom_azimBsShape_Q_fx; +#else model->azimBsShape_dyn_fx[0] = (Word32 *) malloc( sizeof( defaultHRIR_rom_azimBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); IF( model->azimBsShape_dyn_fx[0] == NULL ) { @@ -455,19 +472,33 @@ static ivas_error DefaultBSplineModel_fx( } Copy_Scale_sig_16_32_r( defaultHRIR_rom_azimBsShape_fx, model->azimBsShape_dyn_fx[0], sizeof( defaultHRIR_rom_azimBsShape_fx ) / sizeof( Word16 ), Q30 - defaultHRIR_rom_azimBsShape_Q_fx ); // Q30 model->azimBsShape_fx[0] = model->azimBsShape_dyn_fx[0]; +#endif +#ifdef FIX_2235_TD_RENDERER_WORD16 + IF( ( model->azimKSeq_fx = (Word16 **) malloc( model->elevDim3 * sizeof( Word16 * ) ) ) == NULL || ( model->azimKSeq_Q_fx = (Word16 *) malloc( model->elevDim3 * sizeof( Word16 ) ) ) == NULL ) +#else IF( ( model->azimKSeq_fx = (Word32 **) malloc( model->elevDim3 * sizeof( Word32 * ) ) ) == NULL ) +#endif { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } FOR( i = 0; i < model->elevDim3; i++ ) { +#ifdef FIX_2235_TD_RENDERER_WORD16 + if ( ( model->azimKSeq_fx[i] = (Word16 *) malloc( ( model->azimDim3[i] + 1 ) * sizeof( Word16 * ) ) ) == NULL ) +#else if ( ( model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3[i] + 1 ) * sizeof( Word32 * ) ) ) == NULL ) +#endif { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->azimKSeq_Q_fx[i] = defaultHRIR_rom_azimKSeq_Q_fx; + move16(); +#endif + IF( LT_16( model->azimShapeIdx[i], 0 ) ) { azimSegSamples = 360; @@ -479,10 +510,16 @@ static ivas_error DefaultBSplineModel_fx( move16(); assert( azimSegSamples == 360 / model->azimDim3[i] ); + FOR( j = 0; j < model->azimDim3[i] + 1; j++ ) { +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->azimKSeq_fx[i][j] = extract_l( L_shl_r( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), model->azimKSeq_Q_fx[i] ) ); // Q model->azimKSeq_Q_fx[i] + move16(); +#else model->azimKSeq_fx[i][j] = L_shl_r( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); // Q22 move32(); +#endif } } @@ -490,10 +527,12 @@ static ivas_error DefaultBSplineModel_fx( { case 48000: #ifdef FIX_2235_TD_RENDERER_WORD16 - model->AlphaL_fx = (const Word16 *) defaultHRIR_rom_AlphaL48_fx; // Q14 + model->AlphaL_fx = defaultHRIR_rom_AlphaL48_fx; // Q14 + move16(); model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha48_Q_fx; move16(); - model->AlphaR_fx = (const Word16 *) defaultHRIR_rom_AlphaR48_fx; // Q14 + model->AlphaR_fx = defaultHRIR_rom_AlphaR48_fx; // Q14 + move16(); model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha48_Q_fx; move16(); #else @@ -518,10 +557,12 @@ static ivas_error DefaultBSplineModel_fx( model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha48_Q_fx; move16(); #endif - model->EL_fx = (const Word32 *) defaultHRIR_rom_EL48_fx; // Q28 + model->EL_fx = defaultHRIR_rom_EL48_fx; // Q28 + move16(); model->EL_e = Q31 - defaultHRIR_rom_E48_Q_fx; move16(); - model->ER_fx = (const Word32 *) defaultHRIR_rom_ER48_fx; // Q28 + model->ER_fx = defaultHRIR_rom_ER48_fx; // Q28 + move16(); model->ER_e = Q31 - defaultHRIR_rom_E48_Q_fx; move16(); model->K = defaultHRIR_rom_model_configuration[5]; // Q0 @@ -534,10 +575,12 @@ static ivas_error DefaultBSplineModel_fx( BREAK; case 32000: #ifdef FIX_2235_TD_RENDERER_WORD16 - model->AlphaL_fx = (const Word16 *) defaultHRIR_rom_AlphaL32_fx; // Q14 + model->AlphaL_fx = defaultHRIR_rom_AlphaL32_fx; // Q14 + move16(); model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha32_Q_fx; move16(); - model->AlphaR_fx = (const Word16 *) defaultHRIR_rom_AlphaR32_fx; // Q14 + model->AlphaR_fx = defaultHRIR_rom_AlphaR32_fx; // Q14 + move16(); model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha32_Q_fx; move16(); #else @@ -562,10 +605,12 @@ static ivas_error DefaultBSplineModel_fx( model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha32_Q_fx; move16(); #endif - model->EL_fx = (const Word32 *) defaultHRIR_rom_EL32_fx; // Q28 + model->EL_fx = defaultHRIR_rom_EL32_fx; // Q28 + move16(); model->EL_e = Q31 - defaultHRIR_rom_E32_Q_fx; move16(); - model->ER_fx = (const Word32 *) defaultHRIR_rom_ER32_fx; // Q28 + model->ER_fx = defaultHRIR_rom_ER32_fx; // Q28 + move16(); model->ER_e = Q31 - defaultHRIR_rom_E32_Q_fx; move16(); model->K = ( RESAMPLE_FACTOR_32_48_FX * defaultHRIR_rom_model_configuration[5] + ( 1 << 14 ) - 1 ) >> 14; // Q0 @@ -578,10 +623,10 @@ static ivas_error DefaultBSplineModel_fx( BREAK; case 16000: #ifdef FIX_2235_TD_RENDERER_WORD16 - model->AlphaL_fx = (const Word16 *) defaultHRIR_rom_AlphaL16_fx; // Q14 + model->AlphaL_fx = defaultHRIR_rom_AlphaL16_fx; // Q14 model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha16_Q_fx; move16(); - model->AlphaR_fx = (const Word16 *) defaultHRIR_rom_AlphaR16_fx; // Q14 + model->AlphaR_fx = defaultHRIR_rom_AlphaR16_fx; // Q14 model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha16_Q_fx; move16(); #else @@ -634,8 +679,10 @@ static ivas_error DefaultBSplineModel_fx( modelITD->elevBsStart = defaultHRIR_rom_ITD_elevBsStart; #ifdef FIX_2235_TD_RENDERER_WORD16 - modelITD->elevKSeq_fx = (const Word16 *) defaultHRIR_rom_ITD_elevKSeq_fx; + modelITD->elevKSeq_fx = defaultHRIR_rom_ITD_elevKSeq_fx; + move16(); modelITD->elevKSeq_Q_fx = defaultHRIR_rom_ITD_elevKSeq_Q_fx; + move16(); #else modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_elevKSeq_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); IF( modelITD->elevKSeq_dyn_fx == NULL ) @@ -651,8 +698,10 @@ static ivas_error DefaultBSplineModel_fx( modelITD->azimBsStart = defaultHRIR_rom_ITD_azimBsStart; #ifdef FIX_2235_TD_RENDERER_WORD16 - modelITD->azimKSeq_fx = (const Word16 *) defaultHRIR_rom_ITD_azimKSeq_fx; + modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx; + move16(); modelITD->azimKSeq_Q_fx = defaultHRIR_rom_ITD_azimKSeq_Q_fx; + move16(); #else modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ IF( modelITD->azimKSeq_dyn_fx == NULL ) @@ -671,6 +720,12 @@ static ivas_error DefaultBSplineModel_fx( modelITD->W_fx = modelITD->W_dyn_fx; modelITD->W_e = Q15 - defaultHRIR_rom_ITD_W_Q_fx; move16(); +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; + move16(); + modelITD->azimBsShape_Q_fx = defaultHRIR_rom_ITD_azimBsShape_Q_fx; + move16(); +#else modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_azimBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ IF( modelITD->azimBsShape_dyn_fx == NULL ) { @@ -678,6 +733,13 @@ static ivas_error DefaultBSplineModel_fx( } Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_azimBsShape_fx, modelITD->azimBsShape_dyn_fx, sizeof( defaultHRIR_rom_ITD_azimBsShape_fx ) / sizeof( Word16 ), Q30 - defaultHRIR_rom_ITD_azimBsShape_Q_fx ); // Q22 modelITD->azimBsShape_fx = modelITD->azimBsShape_dyn_fx; +#endif +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->elevBsShape_fx = defaultHRIR_rom_ITD_elevBsShape_fx; + move16(); + modelITD->elevBsShape_Q_fx = defaultHRIR_rom_ITD_elevBsShape_Q_fx; + move16(); +#else modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_elevBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); IF( modelITD->elevBsShape_dyn_fx == NULL ) { @@ -685,6 +747,7 @@ static ivas_error DefaultBSplineModel_fx( } Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_elevBsShape_fx, modelITD->elevBsShape_dyn_fx, sizeof( defaultHRIR_rom_ITD_elevBsShape_fx ) / sizeof( Word16 ), Q30 - defaultHRIR_rom_ITD_elevBsShape_Q_fx ); // Q22 modelITD->elevBsShape_fx = modelITD->elevBsShape_dyn_fx; +#endif HRTF_model_precalc( model ); diff --git a/lib_rend/ivas_prot_rend_fx.h b/lib_rend/ivas_prot_rend_fx.h index b393971b7..c59520d62 100644 --- a/lib_rend/ivas_prot_rend_fx.h +++ b/lib_rend/ivas_prot_rend_fx.h @@ -616,6 +616,13 @@ ivas_error ivas_HRTF_binary_open_buffers_int16( const uint32_t mem_size /* i : size of buffer */ ); +#ifdef FIX_2235_TD_RENDERER_WORD16 +ivas_error ivas_HRTF_binary_open_buffers_int16_ptr( + int16_t ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); +#endif + ivas_error ivas_HRTF_binary_open_buffers_int32( int32_t **buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ @@ -626,6 +633,13 @@ ivas_error ivas_HRTF_binary_open_buffers_int32_ptr( const uint32_t mem_size /* i : size of buffer */ ); +#ifdef FIX_2235_TD_RENDERER_WORD16 +ivas_error ivas_HRTF_binary_open_buffers_int16_ptr_const( + const int16_t ***buffer, /* o : buffer to allocate */ + const uint32_t mem_size /* i : size of buffer */ +); +#endif + ivas_error ivas_HRTF_binary_open_buffers_int32_ptr_const( const int32_t ***buffer, /* o : buffer to allocate */ const uint32_t mem_size /* i : size of buffer */ diff --git a/lib_rend/ivas_rom_TdBinauralRenderer.h b/lib_rend/ivas_rom_TdBinauralRenderer.h index 176dc1f3e..60ef5d4c6 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer.h +++ b/lib_rend/ivas_rom_TdBinauralRenderer.h @@ -52,6 +52,9 @@ extern const Word16 defaultHRIR_rom_azimShapeIdx[15]; extern const Word16 defaultHRIR_rom_azimShapeSampFactor[15]; extern const Word16 defaultHRIR_rom_elevKSeq_Q_fx; extern const Word16 defaultHRIR_rom_elevKSeq_fx[13]; +#ifdef FIX_2235_TD_RENDERER_WORD16 +extern const Word16 defaultHRIR_rom_azimKSeq_Q_fx; +#endif extern const Word16 defaultHRIR_rom_Alpha48_Q_fx; extern const Word16 defaultHRIR_rom_AlphaL48_fx[470 * 128]; /*Q30*/ extern const Word16 defaultHRIR_rom_AlphaR48_fx[470 * 128]; /*Q30*/ diff --git a/lib_rend/ivas_rom_TdBinauralRenderer_fx.c b/lib_rend/ivas_rom_TdBinauralRenderer_fx.c index 980b69242..d9ebceeec 100644 --- a/lib_rend/ivas_rom_TdBinauralRenderer_fx.c +++ b/lib_rend/ivas_rom_TdBinauralRenderer_fx.c @@ -88,6 +88,9 @@ const Word16 defaultHRIR_rom_elevKSeq_Q_fx = 8; const Word16 defaultHRIR_rom_elevKSeq_fx [13] = { -23040, -19200, -15360, -11520, -7680, -3840, 0, 3840, 7680, 11520, 15360, 19200, 23040, }; +#ifdef FIX_2235_TD_RENDERER_WORD16 +const Word16 defaultHRIR_rom_azimKSeq_Q_fx = 6; +#endif const Word16 defaultHRIR_rom_elevBsShape_Q_fx = 15; const Word16 defaultHRIR_rom_elevBsShape_fx[36] = { 32767, 13824, 4096, 512, 0, 0, 16256, 19456, 14976, 8192, 3456, 1024, 128, 0, 0, 2603, 8533, 14976, 19115, 18901, 15360, 10283, 5461, 2304, 683, 85, 0, 0, 85, 683, 2304, 5461, 10325, 15701, 20053, 21845, diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 525e39c1b..0bce8c1bc 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1053,10 +1053,13 @@ typedef struct #ifdef FIX_2235_TD_RENDERER_WORD16 const Word16 *elevKSeq_fx; /* Array, N x elevDim2 x elevDim3 */ Word16 elevKSeq_Q_fx; /* Q-value of elevKSeq_fx */ - const Word32 *elevBsShape_fx; - const Word32 **azimBsShape_fx; - Word32 **azimKSeq_fx; /* Array, length azimDim3+1 */ - const Word16 *AlphaL_fx; /* Array, size AlphaN x K */ + const Word16 *elevBsShape_fx; + Word16 elevBsShape_Q_fx; + const Word16 **azimBsShape_fx; /* 2d Array, length num_unique_azim_splines */ + Word16 *azimBsShape_Q_fx; /* Array, length num_unique_azim_splines, Q-values for each k of azimBsShape_fx[k] */ + Word16 **azimKSeq_fx; /* Array, length azimDim3+1 */ + Word16 *azimKSeq_Q_fx; /* Array, length azimDim3+1, Q-values for each k of azimKSeq_fx[k] */ + const Word16 *AlphaL_fx; /* Array, size AlphaN x K */ Word16 AlphaL_e; const Word16 *AlphaR_fx; /* Array, size AlphaN x K */ #else @@ -1087,10 +1090,11 @@ typedef struct #endif Word32 *EL_dyn_fx; Word32 *ER_dyn_fx; - Word32 *elevBsShape_dyn_fx; #ifdef FIX_2235_TD_RENDERER_WORD16 + Word16 *elevBsShape_dyn_fx; Word16 *elevKSeq_dyn_fx; #else + Word32 *elevBsShape_dyn_fx; Word32 *elevKSeq_dyn_fx; #endif Word16 *elevBsLen_dyn; @@ -1100,7 +1104,11 @@ typedef struct Word16 *azimSegSamples_dyn; Word16 *azimShapeIdx_dyn; Word16 *azimShapeSampFactor_dyn; +#ifdef FIX_2235_TD_RENDERER_WORD16 + Word16 **azimBsShape_dyn_fx; +#else Word32 **azimBsShape_dyn_fx; +#endif } ModelParams_t; @@ -1127,8 +1135,15 @@ typedef struct #endif const Word32 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ Word16 W_e; +#ifdef FIX_2235_TD_RENDERER_WORD16 + const Word16 *azimBsShape_fx; + Word16 azimBsShape_Q_fx; + const Word16 *elevBsShape_fx; + Word16 elevBsShape_Q_fx; +#else const Word32 *azimBsShape_fx; const Word32 *elevBsShape_fx; +#endif /* Pointers for allocation of dynamic memory */ #ifdef FIX_2235_TD_RENDERER_WORD16 @@ -1139,8 +1154,13 @@ typedef struct Word32 *azimKSeq_dyn_fx; #endif Word32 *W_dyn_fx; +#ifdef FIX_2235_TD_RENDERER_WORD16 + Word16 *azimBsShape_dyn_fx; + Word16 *elevBsShape_dyn_fx; +#else Word32 *azimBsShape_dyn_fx; Word32 *elevBsShape_dyn_fx; +#endif Word16 *azimBsLen_dyn_fx; Word16 *azimBsStart_dyn_fx; Word16 *elevBsLen_dyn_fx; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index ecdb22f1e..4e45207ba 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -394,8 +394,18 @@ static ivas_error TDREND_LoadBSplineBinaryITD( fread( modelITD->azimBsStart_dyn_fx, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + ivas_HRTF_binary_open_buffers_int16( &modelITD->azimBsShape_dyn_fx, tmp * sizeof( Word16 ) ); + if ( modelITD->azimBsShape_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &modelITD->azimBsShape_Q_fx, sizeof( Word16 ), 1, f_hrtf ); + fread( modelITD->azimBsShape_dyn_fx, sizeof( Word16 ), tmp, f_hrtf ); +#else ivas_HRTF_binary_open_buffers_int32( &modelITD->azimBsShape_dyn_fx, tmp * sizeof( Word32 ) ); v_tmp16 = (Word16 *) malloc( tmp * sizeof( Word16 ) ); + if ( modelITD->azimBsShape_dyn_fx == NULL || v_tmp16 == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -411,6 +421,7 @@ static ivas_error TDREND_LoadBSplineBinaryITD( modelITD->azimBsShape_dyn_fx[j] = L_shl_r( v_tmp16[j], Q30 - factor_Q ); } free( v_tmp16 ); +#endif fread( &modelITD->azimSegSamples, sizeof( Word16 ), 1, f_hrtf ); @@ -429,6 +440,15 @@ static ivas_error TDREND_LoadBSplineBinaryITD( fread( modelITD->elevBsStart_dyn_fx, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + ivas_HRTF_binary_open_buffers_int16( &modelITD->elevBsShape_dyn_fx, tmp * sizeof( Word16 ) ); + if ( modelITD->elevBsShape_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &modelITD->elevBsShape_Q_fx, sizeof( Word16 ), 1, f_hrtf ); + fread( modelITD->elevBsShape_dyn_fx, sizeof( Word16 ), tmp, f_hrtf ); +#else ivas_HRTF_binary_open_buffers_int32( &modelITD->elevBsShape_dyn_fx, tmp * sizeof( Word32 ) ); if ( modelITD->elevBsShape_dyn_fx == NULL ) { @@ -451,6 +471,7 @@ static ivas_error TDREND_LoadBSplineBinaryITD( modelITD->elevBsShape_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q30 - factor_Q ); } free( v_tmp16 ); +#endif fread( &modelITD->elevSegSamples, sizeof( Word16 ), 1, f_hrtf ); #ifdef FIX_2235_TD_RENDERER_WORD16 @@ -461,8 +482,13 @@ static ivas_error TDREND_LoadBSplineBinaryITD( modelITD->azimKSeq_fx = (const Word32 *) modelITD->azimKSeq_dyn_fx; #endif modelITD->W_fx = (const Word32 *) modelITD->W_dyn_fx; +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->azimBsShape_fx = (const Word16 *) modelITD->azimBsShape_dyn_fx; + modelITD->elevBsShape_fx = (const Word16 *) modelITD->elevBsShape_dyn_fx; +#else modelITD->azimBsShape_fx = (const Word32 *) modelITD->azimBsShape_dyn_fx; modelITD->elevBsShape_fx = (const Word32 *) modelITD->elevBsShape_dyn_fx; +#endif modelITD->azimBsLen = (const Word16 *) modelITD->azimBsLen_dyn_fx; modelITD->azimBsStart = (const Word16 *) modelITD->azimBsStart_dyn_fx; modelITD->elevBsLen = (const Word16 *) modelITD->elevBsLen_dyn_fx; @@ -485,8 +511,10 @@ static ivas_error TDREND_LoadBSplineBinary( { ModelParams_t *model; Word16 i, tmp, factor_Q; +#ifndef FIX_2235_TD_RENDERER_WORD16 Word16 *v_tmp16; Word32 j; +#endif ivas_error error; if ( HrFiltSet_p == NULL || f_hrtf == NULL ) @@ -573,7 +601,12 @@ static ivas_error TDREND_LoadBSplineBinary( ivas_HRTF_binary_open_buffers_int16( &model->azimDim3_dyn, model->elevDim3 * sizeof( Word16 ) ); ivas_HRTF_binary_open_buffers_int16( &model->azim_start_idx_dyn, model->elevDim3 * sizeof( Word16 ) ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + ivas_HRTF_binary_open_buffers_int16_ptr( &model->azimKSeq_fx, model->elevDim3 * sizeof( Word16 * ) ); + ivas_HRTF_binary_open_buffers_int16( &model->azimKSeq_Q_fx, model->elevDim3 * sizeof( Word16 ) ); +#else ivas_HRTF_binary_open_buffers_int32_ptr( &model->azimKSeq_fx, model->elevDim3 * sizeof( float * ) ); +#endif if ( model->azimDim3_dyn == NULL || model->azim_start_idx_dyn == NULL || model->azimKSeq_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); @@ -583,8 +616,16 @@ static ivas_error TDREND_LoadBSplineBinary( { fread( &model->azimDim3_dyn[i], sizeof( Word16 ), 1, f_hrtf ); fread( &model->azim_start_idx_dyn[i], sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + ivas_HRTF_binary_open_buffers_int16( &model->azimKSeq_fx[i], ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word16 ) ); + if ( model->azimKSeq_fx[i] == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &model->azimKSeq_Q_fx[i], sizeof( Word16 ), 1, f_hrtf ); + fread( model->azimKSeq_fx[i], sizeof( Word16 ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf ); +#else ivas_HRTF_binary_open_buffers_int32( &model->azimKSeq_fx[i], ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word32 ) ); - v_tmp16 = (Word16 *) malloc( ( model->azimDim3_dyn[i] + 1 ) * sizeof( Word16 ) ); if ( model->azimKSeq_fx[i] == NULL || v_tmp16 == NULL ) { @@ -601,6 +642,7 @@ static ivas_error TDREND_LoadBSplineBinary( model->azimKSeq_fx[i][j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q22 - factor_Q ); } free( v_tmp16 ); +#endif } fread( &model->AlphaN, sizeof( Word16 ), 1, f_hrtf ); #ifdef FIX_2235_TD_RENDERER_WORD16 @@ -662,8 +704,14 @@ static ivas_error TDREND_LoadBSplineBinary( /* azimuth */ fread( &model->num_unique_azim_splines, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + ivas_HRTF_binary_open_buffers_int16_ptr_const( &model->azimBsShape_fx, model->num_unique_azim_splines * sizeof( Word16 * ) ); + ivas_HRTF_binary_open_buffers_int16_ptr( &model->azimBsShape_dyn_fx, model->num_unique_azim_splines * sizeof( Word16 * ) ); + ivas_HRTF_binary_open_buffers_int16( &model->azimBsShape_Q_fx, model->num_unique_azim_splines * sizeof( Word16 ) ); +#else ivas_HRTF_binary_open_buffers_int32_ptr_const( &model->azimBsShape_fx, model->num_unique_azim_splines * sizeof( float * ) ); ivas_HRTF_binary_open_buffers_int32_ptr( &model->azimBsShape_dyn_fx, model->num_unique_azim_splines * sizeof( float * ) ); +#endif ivas_HRTF_binary_open_buffers_int16( &model->azimSegSamples_dyn, model->num_unique_azim_splines * sizeof( Word16 ) ); if ( model->azimBsShape_fx == NULL || model->azimBsShape_dyn_fx == NULL || model->azimSegSamples_dyn == NULL ) { @@ -673,6 +721,16 @@ static ivas_error TDREND_LoadBSplineBinary( for ( i = 0; i < model->num_unique_azim_splines; i++ ) { fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + ivas_HRTF_binary_open_buffers_int16( &model->azimBsShape_dyn_fx[i], tmp * sizeof( Word16 ) ); + if ( model->azimBsShape_dyn_fx[i] == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &model->azimBsShape_Q_fx[i], sizeof( Word16 ), 1, f_hrtf ); + fread( model->azimBsShape_dyn_fx[i], sizeof( Word16 ), tmp, f_hrtf ); + fread( &model->azimSegSamples_dyn[i], sizeof( Word16 ), 1, f_hrtf ); +#else ivas_HRTF_binary_open_buffers_int32( &model->azimBsShape_dyn_fx[i], tmp * sizeof( Word32 ) ); if ( model->azimBsShape_dyn_fx[i] == NULL ) { @@ -696,6 +754,7 @@ static ivas_error TDREND_LoadBSplineBinary( } fread( &model->azimSegSamples_dyn[i], sizeof( Word16 ), 1, f_hrtf ); free( v_tmp16 ); +#endif } ivas_HRTF_binary_open_buffers_int16( &model->azimShapeIdx_dyn, model->elevDim3 * sizeof( Word16 ) ); if ( model->azimShapeIdx_dyn == NULL ) @@ -725,6 +784,15 @@ static ivas_error TDREND_LoadBSplineBinary( fread( model->elevBsStart_dyn, sizeof( Word16 ), HRTF_MODEL_BSPLINE_NUM_COEFFS, f_hrtf ); fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + ivas_HRTF_binary_open_buffers_int16( &model->elevBsShape_dyn_fx, tmp * sizeof( Word16 ) ); + if ( model->elevBsShape_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &model->elevBsShape_Q_fx, sizeof( Word16 ), 1, f_hrtf ); + fread( model->elevBsShape_dyn_fx, sizeof( Word16 ), tmp, f_hrtf ); +#else v_tmp16 = (Word16 *) malloc( tmp * sizeof( Word16 ) ); ivas_HRTF_binary_open_buffers_int32( &model->elevBsShape_dyn_fx, tmp * sizeof( Word32 ) ); if ( model->elevBsShape_dyn_fx == NULL || v_tmp16 == NULL ) @@ -743,7 +811,7 @@ static ivas_error TDREND_LoadBSplineBinary( model->elevBsShape_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q30 - factor_Q ); } free( v_tmp16 ); - +#endif fread( &model->elevSegSamples, sizeof( Word16 ), 1, f_hrtf ); ivas_HRTF_binary_open_buffers_int32( &model->EL_dyn_fx, model->AlphaN * HRTF_MODEL_N_SECTIONS * sizeof( Word32 ) ); @@ -781,10 +849,11 @@ static ivas_error TDREND_LoadBSplineBinary( model->ER_fx = (const Word32 *) model->ER_dyn_fx; model->elevBsLen = (const Word16 *) model->elevBsLen_dyn; model->elevBsStart = (const Word16 *) model->elevBsStart_dyn; - model->elevBsShape_fx = (const Word32 *) model->elevBsShape_dyn_fx; #ifdef FIX_2235_TD_RENDERER_WORD16 + model->elevBsShape_fx = (const Word16 *) model->elevBsShape_dyn_fx; model->elevKSeq_fx = (const Word16 *) model->elevKSeq_dyn_fx; #else + model->elevBsShape_fx = (const Word32 *) model->elevBsShape_dyn_fx; model->elevKSeq_fx = (const Word32 *) model->elevKSeq_dyn_fx; #endif model->azimDim3 = (const Word16 *) model->azimDim3_dyn; @@ -795,7 +864,11 @@ static ivas_error TDREND_LoadBSplineBinary( for ( i = 0; i < model->num_unique_azim_splines; i++ ) { +#ifdef FIX_2235_TD_RENDERER_WORD16 + model->azimBsShape_fx[i] = (const Word16 *) model->azimBsShape_dyn_fx[i]; +#else model->azimBsShape_fx[i] = (const Word32 *) model->azimBsShape_dyn_fx[i]; +#endif } HRTF_model_precalc( model ); -- GitLab From d1e0136f16c5321ea00ffe698ade1b2fd2ccdd28 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 22 Jan 2026 07:30:24 +0100 Subject: [PATCH 4/8] Fix a few free statements --- lib_rend/ivas_objectRenderer_hrFilt_fx.c | 8 ++++++++ lib_rend/ivas_objectRenderer_mix_fx.c | 13 ++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index f6d041740..79811ab18 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -872,17 +872,25 @@ void BSplineModelEvalDealloc_fx( IF( model->modelROM ) { +#ifndef FIX_2235_TD_RENDERER_WORD16 FOR( i = 0; i < model->num_unique_azim_splines; i++ ) { free( model->azimBsShape_dyn_fx[i] ); } free( model->azimBsShape_dyn_fx ); +#endif free( (void *) model->azimBsShape_fx ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */ +#ifdef FIX_2235_TD_RENDERER_WORD16 + free( model->azimBsShape_Q_fx ); +#endif FOR( i = 0; i < model->elevDim3; i++ ) { free( model->azimKSeq_fx[i] ); } free( model->azimKSeq_fx ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + free( model->azimKSeq_Q_fx ); +#endif IF( modelEval != NULL ) { free( modelEval->hrfModL_fx ); diff --git a/lib_rend/ivas_objectRenderer_mix_fx.c b/lib_rend/ivas_objectRenderer_mix_fx.c index a129352ed..ede82f1aa 100644 --- a/lib_rend/ivas_objectRenderer_mix_fx.c +++ b/lib_rend/ivas_objectRenderer_mix_fx.c @@ -151,27 +151,23 @@ void TDREND_MIX_Dealloc_fx( { BSplineModelEvalDealloc_fx( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval ); } +#ifndef FIX_2235_TD_RENDERER_WORD16 IF( hBinRendererTd->HrFiltSet_p->ModelParams.modelROM ) { IF( hBinRendererTd->HrFiltSet_p->ModelParams.UseItdModel ) { -#ifndef FIX_2235_TD_RENDERER_WORD16 free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.elevKSeq_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.azimKSeq_dyn_fx ); -#endif free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.W_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.azimBsShape_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.elevBsShape_dyn_fx ); } -#ifndef FIX_2235_TD_RENDERER_WORD16 free( hBinRendererTd->HrFiltSet_p->ModelParams.elevKSeq_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParams.AlphaL_dyn_fx ); free( hBinRendererTd->HrFiltSet_p->ModelParams.AlphaR_dyn_fx ); -#endif - free( hBinRendererTd->HrFiltSet_p->ModelParams.elevBsShape_dyn_fx ); } - +#endif IF( EQ_16( hBinRendererTd->HrFiltSet_p->ModelParams.modelROM, 1 ) ) { @@ -419,7 +415,7 @@ static ivas_error DefaultBSplineModel_fx( model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; // Q0 #ifdef FIX_2235_TD_RENDERER_WORD16 - model->elevKSeq_fx = (const Word16 *) defaultHRIR_rom_elevKSeq_fx; + model->elevKSeq_fx = defaultHRIR_rom_elevKSeq_fx; model->elevKSeq_Q_fx = defaultHRIR_rom_elevKSeq_Q_fx; #else model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) ); @@ -449,18 +445,17 @@ static ivas_error DefaultBSplineModel_fx( { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } - model->azimBsShape_dyn_fx = (Word16 **) malloc( sizeof( Word16 * ) ); #else IF( ( model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) ); } model->azimBsShape_dyn_fx = (Word32 **) malloc( sizeof( Word32 * ) ); -#endif IF( model->azimBsShape_dyn_fx == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); } +#endif #ifdef FIX_2235_TD_RENDERER_WORD16 model->azimBsShape_fx[0] = defaultHRIR_rom_azimBsShape_fx; model->azimBsShape_Q_fx[0] = defaultHRIR_rom_azimBsShape_Q_fx; -- GitLab From ebda710cf0d1372c298f547f91d0c3d13419fce7 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 22 Jan 2026 12:07:09 +0100 Subject: [PATCH 5/8] Fix for model->W_fx --- lib_rend/ivas_objectRenderer_hrFilt_fx.c | 8 ++++++-- lib_rend/ivas_objectRenderer_mix_fx.c | 4 ++++ lib_rend/ivas_stat_rend.h | 7 +++++-- lib_util/hrtf_file_reader.c | 18 ++++++++++++++++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index 79811ab18..a3db18093 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -603,7 +603,11 @@ static void GenerateITD_fx( { index = BM_idx[i]; move32(); +#ifdef FIX_2235_TD_RENDERER_WORD16 + temp = W_add( temp, Mpy_32_16_1( modelEval->BM_ITD_fx[i], model->W_fx[index] ) ); +#else temp = W_add( temp, Mpy_32_32( modelEval->BM_ITD_fx[i], model->W_fx[index] ) ); +#endif } itdMod_e = W_norm( temp ); itdMod_e = sub( itdMod_e, 32 ); @@ -648,14 +652,14 @@ static void getPeriodicBSplineSampVec_fx( const Word16 azimKSeq_0_fx, /* i : Knot sequence Q azimKSeq_Q_fx*/ const Word16 azimKSeq_Q_fx, /* i : Q-value of azimKSeq_0_fx */ #else - const Word32 azimKSeq_0_fx, /* i : Knot sequence Q22 */ + const Word32 azimKSeq_0_fx, /* i : Knot sequence Q22 */ #endif const Word16 azimSegSamples, /* i : Samples per segment */ #ifdef FIX_2235_TD_RENDERER_WORD16 const Word16 *azimBsShape_fx, /* i : Basis shape Q azimBsShape_Q_fx */ const Word16 azimBsShape_Q_fx, /* i : Q-value of azimBsShape_fx */ #else - const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ + const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ #endif const Word16 subSampFactor /* i : Subsampling factor */ ) diff --git a/lib_rend/ivas_objectRenderer_mix_fx.c b/lib_rend/ivas_objectRenderer_mix_fx.c index ede82f1aa..9a7771c95 100644 --- a/lib_rend/ivas_objectRenderer_mix_fx.c +++ b/lib_rend/ivas_objectRenderer_mix_fx.c @@ -706,6 +706,9 @@ static ivas_error DefaultBSplineModel_fx( Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_azimKSeq_fx, modelITD->azimKSeq_dyn_fx, ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ), Q22 - defaultHRIR_rom_ITD_azimKSeq_Q_fx ); // Q22 modelITD->azimKSeq_fx = modelITD->azimKSeq_dyn_fx; #endif +#ifdef FIX_2235_TD_RENDERER_WORD16 + modelITD->W_fx = defaultHRIR_rom_ITD_W_fx; +#else modelITD->W_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_W_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */ IF( modelITD->W_dyn_fx == NULL ) { @@ -713,6 +716,7 @@ static ivas_error DefaultBSplineModel_fx( } Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_W_fx, modelITD->W_dyn_fx, sizeof( defaultHRIR_rom_ITD_W_fx ) / sizeof( Word16 ), Q25 - defaultHRIR_rom_ITD_W_Q_fx ); // Q22 modelITD->W_fx = modelITD->W_dyn_fx; +#endif modelITD->W_e = Q15 - defaultHRIR_rom_ITD_W_Q_fx; move16(); #ifdef FIX_2235_TD_RENDERER_WORD16 diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 0bce8c1bc..0cacbd26d 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1129,11 +1129,13 @@ typedef struct Word16 elevKSeq_Q_fx; /* Q-value of elevKSeq_fx */ const Word16 *azimKSeq_fx; /* Array, length azimDim3-2 */ Word16 azimKSeq_Q_fx; /* Q-value of azimKSeq_fx */ + const Word16 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ #else const Word32 *elevKSeq_fx; /* Array, length elevDim3-2 */ const Word32 *azimKSeq_fx; /* Array, length azimDim3-2 */ + const Word32 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ #endif - const Word32 *W_fx; /* Array, size (elevDim3*azimDim3) x K */ + Word16 W_e; #ifdef FIX_2235_TD_RENDERER_WORD16 const Word16 *azimBsShape_fx; @@ -1149,11 +1151,12 @@ typedef struct #ifdef FIX_2235_TD_RENDERER_WORD16 Word16 *elevKSeq_dyn_fx; Word16 *azimKSeq_dyn_fx; + Word16 *W_dyn_fx; #else Word32 *elevKSeq_dyn_fx; Word32 *azimKSeq_dyn_fx; -#endif Word32 *W_dyn_fx; +#endif #ifdef FIX_2235_TD_RENDERER_WORD16 Word16 *azimBsShape_dyn_fx; Word16 *elevBsShape_dyn_fx; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 0dfb3b9d0..dcda32d5d 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -286,9 +286,12 @@ static ivas_error TDREND_LoadBSplineBinaryITD( FILE *f_hrtf /* i : HR filter data file handle */ ) { + Word16 tmp, factor_Q; +#ifndef FIX_2235_TD_RENDERER_WORD16 Word16 *v_tmp16; Word16 j; +#endif if ( modelITD == NULL || f_hrtf == NULL ) { @@ -346,6 +349,16 @@ static ivas_error TDREND_LoadBSplineBinaryITD( #endif fread( &tmp, sizeof( Word16 ), 1, f_hrtf ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + ivas_HRTF_binary_open_buffers_int16( &modelITD->W_dyn_fx, tmp * sizeof( Word16 ) ); + if ( modelITD->W_dyn_fx == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" ); + } + fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf ); + modelITD->W_e = Q15 - factor_Q; + fread( modelITD->W_dyn_fx, sizeof( Word16 ), tmp, f_hrtf ); +#else ivas_HRTF_binary_open_buffers_int32( &modelITD->W_dyn_fx, tmp * sizeof( Word32 ) ); if ( modelITD->W_dyn_fx == NULL ) { @@ -366,7 +379,7 @@ static ivas_error TDREND_LoadBSplineBinaryITD( modelITD->W_dyn_fx[j] = L_shl_r( L_deposit_l( v_tmp16[j] ), Q25 - factor_Q ); } free( v_tmp16 ); - +#endif /* azimuth */ ivas_HRTF_binary_open_buffers_int16( &modelITD->azimBsLen_dyn_fx, HRTF_MODEL_BSPLINE_NUM_COEFFS * sizeof( Word16 ) ); if ( modelITD->azimBsLen_dyn_fx == NULL ) @@ -456,11 +469,12 @@ static ivas_error TDREND_LoadBSplineBinaryITD( #ifdef FIX_2235_TD_RENDERER_WORD16 modelITD->elevKSeq_fx = (const Word16 *) modelITD->elevKSeq_dyn_fx; modelITD->azimKSeq_fx = (const Word16 *) modelITD->azimKSeq_dyn_fx; + modelITD->W_fx = (const Word16 *) modelITD->W_dyn_fx; #else modelITD->elevKSeq_fx = (const Word32 *) modelITD->elevKSeq_dyn_fx; modelITD->azimKSeq_fx = (const Word32 *) modelITD->azimKSeq_dyn_fx; -#endif modelITD->W_fx = (const Word32 *) modelITD->W_dyn_fx; +#endif #ifdef FIX_2235_TD_RENDERER_WORD16 modelITD->azimBsShape_fx = (const Word16 *) modelITD->azimBsShape_dyn_fx; modelITD->elevBsShape_fx = (const Word16 *) modelITD->elevBsShape_dyn_fx; -- GitLab From 66db8855e25d2dd3801259989ff161b6c814ae98 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 22 Jan 2026 12:38:17 +0100 Subject: [PATCH 6/8] Add missing free for azimKSeq_Q_fx --- lib_rend/ivas_hrtf_fx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_rend/ivas_hrtf_fx.c b/lib_rend/ivas_hrtf_fx.c index c597514f1..f7b607304 100644 --- a/lib_rend/ivas_hrtf_fx.c +++ b/lib_rend/ivas_hrtf_fx.c @@ -87,6 +87,9 @@ void ivas_HRTF_td_binary_close_fx( free( ( *hHrtfTD )->ModelParams.azimKSeq_fx[i] ); } free( ( *hHrtfTD )->ModelParams.azimKSeq_fx ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + free( ( *hHrtfTD )->ModelParams.azimKSeq_Q_fx ); +#endif IF( ( *hHrtfTD )->ModelEval.hrfModR_fx != NULL ) { free( ( *hHrtfTD )->ModelEval.hrfModL_fx ); -- GitLab From 85f7fb46f335c49418c4f5973ae2d0c60e703f63 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 22 Jan 2026 12:56:25 +0100 Subject: [PATCH 7/8] Add missing free --- lib_rend/ivas_hrtf_fx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib_rend/ivas_hrtf_fx.c b/lib_rend/ivas_hrtf_fx.c index f7b607304..a892e999a 100644 --- a/lib_rend/ivas_hrtf_fx.c +++ b/lib_rend/ivas_hrtf_fx.c @@ -131,6 +131,9 @@ void ivas_HRTF_td_binary_close_fx( free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn_fx[i] ); } free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn_fx ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + free( ( *hHrtfTD )->ModelParams.azimBsShape_Q_fx ); +#endif free( (void *) ( *hHrtfTD )->ModelParams.azimBsShape_fx ); /* 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 < ( *hHrtfTD )->ModelParams.elevDim3; i++ ) @@ -138,6 +141,9 @@ void ivas_HRTF_td_binary_close_fx( free( ( *hHrtfTD )->ModelParams.azimKSeq_fx[i] ); } free( ( *hHrtfTD )->ModelParams.azimKSeq_fx ); +#ifdef FIX_2235_TD_RENDERER_WORD16 + free( ( *hHrtfTD )->ModelParams.azimKSeq_Q_fx ); +#endif free( ( *hHrtfTD )->ModelParams.EL_dyn_fx ); free( ( *hHrtfTD )->ModelParams.ER_dyn_fx ); -- GitLab From 7545a6cb127d618f591a651dceb7379831fdd5f0 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Fri, 23 Jan 2026 13:53:28 +0100 Subject: [PATCH 8/8] Move define to BE section. Remove unnecessary abs and add assert --- lib_com/options.h | 2 +- lib_rend/ivas_objectRenderer_hrFilt_fx.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index cddf8b057..b6b54099c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -101,13 +101,13 @@ #define FIX_BASOP_2332_ASAN_OVERFLOW_IN_EXT_DIRAC_REND /* Nokia: basop issue 2332: Uses predefined memory sizes instead computing wrong */ #define FIX_BASOP_2333_MCMASA_ANA_MEMORY_LEAK /* Nokia: basop issue 2333: Add missing free for direction_vector_e to ivas_mcmasa_ana_fx.c */ #define HARM_COREDECODER_FUNCTIONS /* VA: basop issue 2347: Remove various duplicated code in core-decoder */ +#define FIX_2235_TD_RENDERER_WORD16 /* Eri: Use Word16 in TD renderer without converting to Word32 */ /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ /* any switch which is non-be wrt. TS 26.251 V3.0 */ -#define FIX_2235_TD_RENDERER_WORD16 /* Eri: Use Word16 in TD renderer without converting to Word32 */ #define FIX_2250_LARGE_DIFFERENCES_BETWEEN_BASOP_AND_FLOAT /* Dolby: Issue 2250: random vector generation in GenShapedSHBExcitation() */ #define FIX_2320_OOB_SCE_SWITCHING /* VA: basop issue 2320: Correct the length of the buffer to be scaled in SCE/CPE switching */ #define FIX_2302_LSF_CDBK_THRESHOLD /* VA: basop issue 2302: fix threshold for LSF Q codebook-type decision */ diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index a3db18093..f6fa9b50d 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -818,7 +818,8 @@ static void getStandardBSplineSampVec_fx( d = sub( shl( sub( BsLen[shape_idx], 1 ), 1 ), d ); } #ifdef FIX_2235_TD_RENDERER_WORD16 - BfVec_fx[i] = L_shl( L_deposit_l( BsShape_fx[add( BsStart[shape_idx], abs_s( d ) )] ), 30 - BsShape_Q_fx ); /* Q30 */ + assert( d >= 0 && d < BsLen[shape_idx] ); + BfVec_fx[i] = L_shl( L_deposit_l( BsShape_fx[add( BsStart[shape_idx], d )] ), 30 - BsShape_Q_fx ); /* Q30 */ #else BfVec_fx[i] = BsShape_fx[add( BsStart[shape_idx], abs_s( d ) )]; /*TT, verify if abs is needed */ move32(); -- GitLab