From 34321f15ff72732103d730cd1ed67bd258e3a33a Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 17 Jul 2025 15:34:48 +0200 Subject: [PATCH] Port MR1531 under define CONF_DISTATT --- apps/decoder.c | 7 + lib_com/common_api_types.h | 4 +- lib_com/options.h | 1 + lib_dec/ivas_objectRenderer_internal.c | 8 + lib_dec/lib_dec.c | 3 + lib_rend/ivas_objectRenderer.c | 65 +++++++- lib_rend/ivas_objectRenderer_sources.c | 60 +++++++- lib_rend/ivas_prot_rend.h | 11 +- lib_rend/ivas_render_config.c | 5 + lib_util/render_config_reader.c | 202 ++++++++++++++++++++++++- lib_util/render_config_reader.h | 6 + 11 files changed, 361 insertions(+), 11 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 1df9c9353..8f88cb35f 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -608,6 +608,13 @@ int main( fprintf( stderr, "Failed to get directivity patterns for one or more of IDs: %d %d %d %d\n\n", arg.directivityPatternId[0], arg.directivityPatternId[1], arg.directivityPatternId[2], arg.directivityPatternId[3] ); goto cleanup; } +#ifdef CONF_DISTATT + if ( ( error = RenderConfigReader_getDistanceAttenuation( renderConfigReader, renderConfig.distAtt ) ) != IVAS_ERR_OK ) + { + fprintf( stderr, "Failed to get Distance Attenuation \n\n" ); + goto cleanup; + } +#endif if ( ( arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || arg.outputConfig == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) { diff --git a/lib_com/common_api_types.h b/lib_com/common_api_types.h index 551c5036d..d6960671d 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -325,7 +325,9 @@ typedef struct _IVAS_RENDER_CONFIG IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcoustics; ISAR_SPLIT_REND_CONFIG_DATA split_rend_config; float directivity[IVAS_MAX_NUM_OBJECTS * 3]; - +#ifdef CONF_DISTATT + float distAtt[3]; +#endif } IVAS_RENDER_CONFIG_DATA, *IVAS_RENDER_CONFIG_HANDLE; typedef struct diff --git a/lib_com/options.h b/lib_com/options.h index 8e261a70e..6320c982c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -185,6 +185,7 @@ #define FIX_WARNING_RENDER_CONFIG /* Orange: fix warning on windows build */ #define NONBE_FIX_991_PARAMBIN_BINARY_HRTF /* Nokia: issue #991: fix using of binary file HRTF in ParamBin (to actiate when USE_NEW_HRTF_BINARY_FILE_FORMAT and FIX_777_COMBI_RENDER_CONFIG_FILE are on )*/ +#define CONF_DISTATT /* Eri: Make distance attenuation configurable */ /* #################### End BASOP porting switches ############################ */ diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index d28bd60af..823844b9a 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -61,8 +61,13 @@ ivas_error ivas_td_binaural_open( num_src = st_ivas->nchan_ism; } +#ifdef CONF_DISTATT + return ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, num_src, st_ivas->ivas_format, + st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hRenderConfig->distAtt, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); +#else return ivas_td_binaural_open_unwrap( &st_ivas->hHrtfTD, st_ivas->hDecoderConfig->output_Fs, num_src, st_ivas->ivas_format, st_ivas->transport_config, st_ivas->hRenderConfig->directivity, st_ivas->hTransSetup, &st_ivas->hBinRendererTd, &st_ivas->binaural_latency_ns ); +#endif } @@ -272,6 +277,9 @@ ivas_error ivas_td_binaural_renderer_sf_splitBinaural( st_ivas->ivas_format, st_ivas->transport_config, st_ivas->hRenderConfig->directivity, +#ifdef CONF_DISTATT + st_ivas->hRenderConfig->distAtt, +#endif st_ivas->hTransSetup, &st_ivas->hTdRendHandles[i], &st_ivas->binaural_latency_ns ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index e08b838e3..bd3f60c94 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2169,6 +2169,9 @@ ivas_error IVAS_DEC_FeedRenderConfig( mvr2r( renderConfig.roomAcoustics.pAcoustic_dsr, hRenderConfig->roomAcoustics.pAcoustic_dsr, CLDFB_NO_CHANNELS_MAX ); mvr2r( renderConfig.directivity, hRenderConfig->directivity, 3 * MAX_NUM_OBJECTS ); +#ifdef CONF_DISTATT + mvr2r( renderConfig.distAtt, hRenderConfig->distAtt, 3 ); +#endif hRenderConfig->split_rend_config = renderConfig.split_rend_config; diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 14ae95384..2e98f7de7 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -60,12 +60,15 @@ static void angles_to_vec( const float radius, const float azimuth, const float *---------------------------------------------------------------------*/ ivas_error ivas_td_binaural_open_unwrap( - TDREND_HRFILT_FiltSet_t **hHrtfTD, /* i/o: HR filter model (from file or NULL) */ - const int32_t output_Fs, /* i : Output sampling rate */ - const int16_t nchan_transport, /* i : Number of channels */ - const IVAS_FORMAT ivas_format, /* i : IVAS format (ISM/MC) */ - const AUDIO_CONFIG transport_config, /* i : Transport configuration */ - const float *directivity, /* i : Directivity pattern (used for ISM) */ + TDREND_HRFILT_FiltSet_t **hHrtfTD, /* i/o: HR filter model (from file or NULL) */ + const int32_t output_Fs, /* i : Output sampling rate */ + const int16_t nchan_transport, /* i : Number of channels */ + const IVAS_FORMAT ivas_format, /* i : IVAS format (ISM/MC) */ + const AUDIO_CONFIG transport_config, /* i : Transport configuration */ + const float *directivity, /* i : Directivity pattern (used for ISM) */ +#ifdef CONF_DISTATT + const float *distAtt, /* i : Distance attenuation (used for ISM) */ +#endif const IVAS_OUTPUT_SETUP hTransSetup, /* i : Loudspeaker layout */ BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd, /* o : TD renderer handle */ int32_t *binaural_latency_ns /* i : Binauralization delay */ @@ -79,6 +82,9 @@ ivas_error ivas_td_binaural_open_unwrap( float Pos[3]; float Dir[3]; TDREND_DirAtten_t *DirAtten_p; +#ifdef CONF_DISTATT + TDREND_DistAtten_t DistAtten; +#endif int16_t nchan_rend; ivas_error error; @@ -184,6 +190,13 @@ ivas_error ivas_td_binaural_open_unwrap( DirAtten_p->ConeOuterAngle = 360.0f; DirAtten_p->ConeOuterGain = 1.0f; +#ifdef CONF_DISTATT + DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; + DistAtten.MaxDist = 15.75f; + DistAtten.RefDist = 1.0f; + DistAtten.RollOffFactor = 1.0f; +#endif + if ( ( error = TDREND_MIX_SRC_SetPos( pBinRendTd, nS, Pos ) ) != IVAS_ERR_OK ) { return error; @@ -203,6 +216,12 @@ ivas_error ivas_td_binaural_open_unwrap( { return error; } +#ifdef CONF_DISTATT + if ( ( error = TDREND_MIX_SRC_SetDistAtten( pBinRendTd, nS, &DistAtten ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif } } @@ -224,11 +243,32 @@ ivas_error ivas_td_binaural_open_unwrap( DirAtten_p->ConeOuterAngle = directivity[nS * 3 + 1]; DirAtten_p->ConeOuterGain = directivity[nS * 3 + 2]; } - +#ifdef CONF_DISTATT + if ( NULL == distAtt ) + { + DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; + DistAtten.MaxDist = 15.75f; + DistAtten.RefDist = 1.0f; + DistAtten.RollOffFactor = 1.0f; + } + else + { + DistAtten.DistAttenModel = TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED; + DistAtten.MaxDist = distAtt[0]; + DistAtten.RefDist = distAtt[1]; + DistAtten.RollOffFactor = distAtt[2]; + } +#endif if ( ( error = TDREND_MIX_SRC_SetDirAtten( pBinRendTd, nS, DirAtten_p ) ) != IVAS_ERR_OK ) { return error; } +#ifdef CONF_DISTATT + if ( ( error = TDREND_MIX_SRC_SetDistAtten( pBinRendTd, nS, &DistAtten ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif } } @@ -638,6 +678,9 @@ ivas_error ivas_td_binaural_open_ext( IVAS_OUTPUT_SETUP hTransSetup; ivas_error error; +#ifdef CONF_DISTATT + float *distAtt = NULL; +#endif float *directivity = NULL; if ( inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM ) @@ -667,8 +710,16 @@ ivas_error ivas_td_binaural_open_ext( if ( NULL != hRendCfg ) { directivity = hRendCfg->directivity; +#ifdef CONF_DISTATT + distAtt = hRendCfg->distAtt; +#endif } + +#ifdef CONF_DISTATT + return ivas_td_binaural_open_unwrap( pTDRend->hHrtfTD, outFs, nchan_transport, ivas_format, transport_config, directivity, distAtt, hTransSetup, &pTDRend->hBinRendererTd, &pTDRend->binaural_latency_ns ); +#else return ivas_td_binaural_open_unwrap( pTDRend->hHrtfTD, outFs, nchan_transport, ivas_format, transport_config, directivity, hTransSetup, &pTDRend->hBinRendererTd, &pTDRend->binaural_latency_ns ); +#endif } diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index e772192c3..c1eaef409 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -51,6 +51,10 @@ static void TDREND_SRC_SPATIAL_Init( TDREND_SRC_SPATIAL_t *SrcSpatial_p, const T static void TDREND_SRC_SPATIAL_SetDirAtten( TDREND_SRC_SPATIAL_t *SrcSpatial_p, const TDREND_DirAtten_t *DirAtten_p ); +#ifdef CONF_DISTATT +static void TDREND_SRC_SPATIAL_SetDistAtten( TDREND_SRC_SPATIAL_t *SrcSpatial_p, const TDREND_DistAtten_t *DistAtten_p ); +#endif + static float TDREND_SRC_SPATIAL_GetDirGain( const TDREND_DirAtten_t *DirAtten_p, const float *Front_p, const float *RelPos_p ); static float TDREND_SRC_SPATIAL_GetDistGain( const TDREND_DistAtten_t *DistAtten_p, const float Dist ); @@ -153,6 +157,33 @@ ivas_error TDREND_MIX_SRC_SetDirAtten( return IVAS_ERR_OK; } +#ifdef CONF_DISTATT +/*-------------------------------------------------------------------* + * TDREND_MIX_SRC_SetDistAtten() + * + * Set distance attenuation for the mixer. + --------------------------------------------------------------------*/ + +ivas_error TDREND_MIX_SRC_SetDistAtten( + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const int16_t SrcInd, /* i : Source index */ + const TDREND_DistAtten_t *DistAtten_p /* i : Distance attenuation specifier */ +) +{ + TDREND_SRC_SPATIAL_t *SrcSpatial_p; + if ( SrcInd > hBinRendererTd->MaxSrcInd ) + { + return ( IVAS_ERROR( IVAS_ERR_INVALID_INDEX, "Index exceeds max index\n" ) ); + } + else + { + SrcSpatial_p = hBinRendererTd->Sources[SrcInd]->SrcSpatial_p; + TDREND_SRC_SPATIAL_SetDistAtten( SrcSpatial_p, DistAtten_p ); + } + + return IVAS_ERR_OK; +} +#endif /*-------------------------------------------------------------------* * TDREND_MIX_SRC_SetPlayState() @@ -483,7 +514,27 @@ static void TDREND_SRC_SPATIAL_SetDirAtten( return; } +#ifdef CONF_DISTATT +/*-------------------------------------------------------------------* + * TDREND_SRC_SPATIAL_SetDistAtten() + * + * Sets the distance attenuation. + --------------------------------------------------------------------*/ + +static void TDREND_SRC_SPATIAL_SetDistAtten( + TDREND_SRC_SPATIAL_t *SrcSpatial_p, + const TDREND_DistAtten_t *DistAtten_p ) +{ + /* Set distance attenuation */ + SrcSpatial_p->DistAttenEnabled = TRUE; + SrcSpatial_p->DistAtten.DistAttenModel = DistAtten_p->DistAttenModel; + SrcSpatial_p->DistAtten.MaxDist = DistAtten_p->MaxDist; + SrcSpatial_p->DistAtten.RefDist = DistAtten_p->RefDist; + SrcSpatial_p->DistAtten.RollOffFactor = DistAtten_p->RollOffFactor; + return; +} +#endif /*-------------------------------------------------------------------* * TDREND_SRC_SPATIAL_GetDirGain() * @@ -557,7 +608,11 @@ static float TDREND_SRC_SPATIAL_GetDistGain( switch ( DistAtten_p->DistAttenModel ) { case TDREND_DIST_ATTEN_MODEL_INV_DIST: +#ifdef CONF_DISTATT + DistGain = powf( DistAtten_p->RefDist / Dist2, DistAtten_p->RollOffFactor ); +#else DistGain = DistAtten_p->RefDist / ( DistAtten_p->RefDist + DistAtten_p->RollOffFactor * ( Dist2 - DistAtten_p->RefDist ) ); +#endif break; case TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED: @@ -570,8 +625,11 @@ static float TDREND_SRC_SPATIAL_GetDistGain( { Dist2 = DistAtten_p->MaxDist; } - +#ifdef CONF_DISTATT + DistGain = powf( DistAtten_p->RefDist / Dist2, DistAtten_p->RollOffFactor ); +#else DistGain = DistAtten_p->RefDist / ( DistAtten_p->RefDist + DistAtten_p->RollOffFactor * ( Dist2 - DistAtten_p->RefDist ) ); +#endif break; } diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 876a6f91c..bcfdb294a 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -634,6 +634,9 @@ ivas_error ivas_td_binaural_open_unwrap( const IVAS_FORMAT ivas_format, /* i : IVAS format (ISM/MC) */ const AUDIO_CONFIG transport_config, /* i : Transport configuration */ const float *directivity, /* i : Directivity pattern (used for ISM) */ +#ifdef CONF_DISTATT + const float *distAtt, /* i : Distance attenuation (used for ISM) */ +#endif const IVAS_OUTPUT_SETUP hTransSetup, /* i : Loudspeaker layout */ BINAURAL_TD_OBJECT_RENDERER_HANDLE *hBinRendererTd, /* o : TD renderer handle */ int32_t *binaural_latency_ns /* i : Binauralization delay */ @@ -722,7 +725,13 @@ ivas_error TDREND_MIX_SRC_SetDirAtten( const int16_t SrcInd, /* i : Source index */ const TDREND_DirAtten_t *DirAtten_p /* i : Directional attenuation specifier */ ); - +#ifdef CONF_DISTATT +ivas_error TDREND_MIX_SRC_SetDistAtten( + BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ + const int16_t SrcInd, /* i : Source index */ + const TDREND_DistAtten_t *DistAtten_p /* i : Distance attenuation specifier */ +); +#endif ivas_error TDREND_MIX_SRC_SetPlayState( BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle */ const int16_t SrcInd, /* i : Source index */ diff --git a/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index 081c0940d..7ab194970 100644 --- a/lib_rend/ivas_render_config.c +++ b/lib_rend/ivas_render_config.c @@ -131,6 +131,11 @@ ivas_error ivas_render_config_init_from_rom( ( *hRenderConfig )->directivity[i * 3 + 1] = 360.0f; /* Back cone */ ( *hRenderConfig )->directivity[i * 3 + 2] = 1.0f; /* Back attenuation */ } +#ifdef CONF_DISTATT + ( *hRenderConfig )->distAtt[0] = 15.75f; /* Default max dist */ + ( *hRenderConfig )->distAtt[1] = 1.0f; /* Default ref dist */ + ( *hRenderConfig )->distAtt[2] = 1.0f; /* Default rolloff factor */ +#endif ( *hRenderConfig )->split_rend_config.splitRendBitRate = SPLIT_REND_768k; ( *hRenderConfig )->split_rend_config.dof = 3; ( *hRenderConfig )->split_rend_config.hq_mode = 0; diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index 25cefcfbe..af145a602 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -124,6 +124,9 @@ struct RenderConfigReader AcousticEnv *pAE; /* Acoustic environments */ uint32_t nDP; /* Number of directivity patterns */ DirectrivityPat *pDP; /* Directivity Pattern */ +#ifdef CONF_DISTATT + float distAtt[3]; /* [MaxDist, RefDist, Rolloff] */ +#endif }; @@ -1000,6 +1003,77 @@ static ivas_error get_bin_outer_attenuation( return IVAS_ERR_OK; } +#ifdef CONF_DISTATT +/*-----------------------------------------------------------------------------------------* + * Function get_bin_max_dist () + * Gets a Maximum Distance value [1.0, 64.0] + *-----------------------------------------------------------------------------------------*/ + +static ivas_error get_bin_max_dist( + RenderConfigReader *this, /* i/o : Render config reader handle */ + float *pResult /* o : Attenuation value */ +) +{ + ivas_error error; + uint32_t value; + + if ( ( error = read_bin_bits( this, &value, 6 ) ) != IVAS_ERR_OK ) + { + return error; + } + + *pResult = usdequant( (int16_t) value, 1.0f, 1.0f ); + + return IVAS_ERR_OK; +} + +/*-----------------------------------------------------------------------------------------* + * Function get_bin_ref_dist () + * Gets a Reference Distance value [0.1, 6.4] + *-----------------------------------------------------------------------------------------*/ + +static ivas_error get_bin_ref_dist( + RenderConfigReader *this, /* i/o : Render config reader handle */ + float *pResult /* o : Attenuation value */ +) +{ + ivas_error error; + uint32_t value; + + if ( ( error = read_bin_bits( this, &value, 6 ) ) != IVAS_ERR_OK ) + { + return error; + } + + *pResult = usdequant( (int16_t) value, 0.1f, 0.1f ); + + return IVAS_ERR_OK; +} + +/*-----------------------------------------------------------------------------------------* + * Function get_bin_rolloff () + * Gets a Rollof Factor [0.0, 4.0] + *-----------------------------------------------------------------------------------------*/ + +static ivas_error get_bin_rolloff( + RenderConfigReader *this, /* i/o : Render config reader handle */ + float *pResult /* o : Attenuation value */ +) +{ + ivas_error error; + uint32_t value; + + if ( ( error = read_bin_bits( this, &value, 6 ) ) != IVAS_ERR_OK ) + { + return error; + } + + *pResult = usdequant( (int16_t) value, 0.0f, 0.1f ); + + return IVAS_ERR_OK; +} + +#endif /*-----------------------------------------------------------------------------------------* * Function read_txt_vector() @@ -1128,7 +1202,9 @@ ivas_error RenderConfigReader_checkValues( pRoom_acoustics = &hRenderConfig->roomAcoustics; tab_value_err_count = 0; int16_t wall_idx; - +#ifdef CONF_DISTATT + int16_t i; +#endif /* Verify the number of frequency bands in the config input data */ if ( ( pRoom_acoustics->nBands > N_BANDS_MAX ) || ( pRoom_acoustics->nBands < N_BANDS_MIN ) ) @@ -1245,6 +1321,22 @@ ivas_error RenderConfigReader_checkValues( pRoom_acoustics->AbsCoeff[wall_idx] = ER_MAX_ABS_COEFF; } } + +#ifdef CONF_DISTATT + /* Verify range of distance attenuation parameters: 0.1 <= distAtt[0] <= distAtt[1] */ + /* 0.0 <= distAtt[2] <= 10.0 */ + hRenderConfig->distAtt[0] = max( 0.1f, hRenderConfig->distAtt[0] ); + hRenderConfig->distAtt[1] = max( hRenderConfig->distAtt[0], hRenderConfig->distAtt[1] ); + hRenderConfig->distAtt[2] = max( 0.0f, min( 10.0f, hRenderConfig->distAtt[2] ) ); + + /* Verify range of directivity patterns */ + for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) + { + hRenderConfig->directivity[i * 3] = max( 0.0f, min( 360.0f, hRenderConfig->directivity[i * 3] ) ); + hRenderConfig->directivity[i * 3 + 1] = max( 0.0f, min( 360.0f, hRenderConfig->directivity[i * 3 + 1] ) ); + hRenderConfig->directivity[i * 3 + 2] = max( 0.0f, min( 1.0f, hRenderConfig->directivity[i * 3 + 2] ) ); + } +#endif } @@ -1287,6 +1379,9 @@ ivas_error RenderConfigReader_open( pSelf->pAE = NULL; pSelf->nDP = 0; pSelf->pDP = NULL; +#ifdef CONF_DISTATT + pSelf->distAtt[0] = -1; +#endif *ppRenderConfigReader = pSelf; return IVAS_ERR_OK; @@ -1806,6 +1901,36 @@ static ivas_error RenderConfigReader_readBinary( } } } +#ifdef CONF_DISTATT + /**********************************/ + /* Read the distance attenuation */ + /**********************************/ + + /* Has distance attenuation */ + if ( ( error = read_bin_bool( pRenderConfigReader, &value ) ) != IVAS_ERR_OK ) + { + return error; + } + if ( value == true ) + { + /* Read the Max Distance */ + if ( ( error = get_bin_max_dist( pRenderConfigReader, &pRenderConfigReader->distAtt[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + /* Read the Ref Distance */ + if ( ( error = get_bin_ref_dist( pRenderConfigReader, &pRenderConfigReader->distAtt[1] ) ) != IVAS_ERR_OK ) + { + return error; + } + /* Read the Rolloff Facto r*/ + if ( ( error = get_bin_rolloff( pRenderConfigReader, &pRenderConfigReader->distAtt[2] ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + /* Cleanup */ free( pRenderConfigReader->pBitstream ); @@ -2656,6 +2781,53 @@ ivas_error RenderConfigReader_read( free( pValue ); accDPIdx++; } +#ifdef CONF_DISTATT + else if ( strcmp( chapter, "DISTANCEATTENUATION" ) == 0 ) + { + params_idx = 0; + pValue = (char *) calloc( strlen( pParams ), sizeof( char ) ); + + /* Set default values if parameters are only partially specified */ + pRenderConfigReader->distAtt[0] = 15.75f; + pRenderConfigReader->distAtt[1] = 1.0f; + pRenderConfigReader->distAtt[2] = 1.0f; + + while ( sscanf( pParams + params_idx, "%64[^=]=%[^;];", item, pValue ) == 2 ) + { + params_idx += (int32_t) ( strlen( item ) + strlen( pValue ) + 2 ); + + if ( strcmp( item, "MAXDIST" ) == 0 ) + { + /* Read the Maximum distance */ + if ( !sscanf( pValue, "%f", &pRenderConfigReader->distAtt[0] ) ) + { + errorHandler( item, ERROR_VALUE_INVALID ); + return IVAS_ERR_INVALID_RENDER_CONFIG; + } + } + if ( strcmp( item, "REFDIST" ) == 0 ) + { + /* Read the Reference distance */ + if ( !sscanf( pValue, "%f", &pRenderConfigReader->distAtt[1] ) ) + { + errorHandler( item, ERROR_VALUE_INVALID ); + return IVAS_ERR_INVALID_RENDER_CONFIG; + } + } + if ( strcmp( item, "ROLLOFFFACTOR" ) == 0 ) + { + /* Read the Rolloff Factor */ + if ( !sscanf( pValue, "%f", &pRenderConfigReader->distAtt[2] ) ) + { + errorHandler( item, ERROR_VALUE_INVALID ); + return IVAS_ERR_INVALID_RENDER_CONFIG; + } + } + } + + free( pValue ); + } +#endif else if ( strcmp( chapter, "GENERAL" ) == 0 && strlen( pParams ) != 0 ) { params_idx = 0; @@ -2906,6 +3078,34 @@ ivas_error RenderConfigReader_getDirectivity( return IVAS_ERR_OK; } +#ifdef CONF_DISTATT +/*------------------------------------------------------------------------------------------* + * RenderConfigReader_getDistanceAttenuation() + * + * Gets Distance Attenuation + *------------------------------------------------------------------------------------------*/ + +ivas_error RenderConfigReader_getDistanceAttenuation( + RenderConfigReader *pRenderConfigReader, /* i : RenderConfigReader handle */ + float *distAtt /* o : Distance attenuation */ +) +{ + if ( pRenderConfigReader->distAtt[0] == -1 ) + { + distAtt[0] = 15.75f; + distAtt[1] = 1.0f; + distAtt[2] = 1.0f; + } + else + { + distAtt[0] = pRenderConfigReader->distAtt[0]; + distAtt[1] = pRenderConfigReader->distAtt[1]; + distAtt[2] = pRenderConfigReader->distAtt[2]; + } + + return IVAS_ERR_OK; +} +#endif /*------------------------------------------------------------------------------------------* * RenderConfigReader_close() diff --git a/lib_util/render_config_reader.h b/lib_util/render_config_reader.h index 5edf73ded..561e05f31 100644 --- a/lib_util/render_config_reader.h +++ b/lib_util/render_config_reader.h @@ -62,6 +62,12 @@ ivas_error RenderConfigReader_getDirectivity( uint16_t *pId, /* i : Directivity pattern ID */ float *directivity /* o : Target directivity */ ); +#ifdef CONF_DISTATT +ivas_error RenderConfigReader_getDistanceAttenuation( + RenderConfigReader *pRenderConfigReader, /* i : RenderConfigReader handle */ + float *distAtt /* o : Distance attenuation */ +); +#endif /* Verifies configuration parameters */ ivas_error RenderConfigReader_checkValues( IVAS_RENDER_CONFIG_HANDLE hRenderConfig /* o : Renderer configuration handle */ -- GitLab