From 25ff9684e737cf16a1ad071e25fab7b4d070899f Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 30 Apr 2024 08:07:52 +0200 Subject: [PATCH 1/7] Add configurable distance attenuation under CONF_DISTATT --- apps/decoder.c | 8 +- lib_com/common_api_types.h | 3 + lib_com/options.h | 1 + lib_dec/ivas_objectRenderer_internal.c | 5 + lib_dec/lib_dec.c | 3 + lib_rend/ivas_objectRenderer.c | 51 +++++- lib_rend/ivas_objectRenderer_sources.c | 60 ++++++- lib_rend/ivas_prot_rend.h | 11 +- lib_util/render_config_reader.c | 202 +++++++++++++++++++++++ lib_util/render_config_reader.h | 6 + scripts/reverb/text_to_binary_payload.py | 13 +- 11 files changed, 352 insertions(+), 11 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index de0dd8bca9..f176a3dd4c 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -660,7 +660,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 #ifdef SPLIT_REND_WITH_HEAD_ROT 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 1d4cde9680..3ec839868d 100644 --- a/lib_com/common_api_types.h +++ b/lib_com/common_api_types.h @@ -325,6 +325,9 @@ typedef struct _IVAS_RENDER_CONFIG ISAR_SPLIT_REND_CONFIG_DATA split_rend_config; #endif float directivity[IVAS_MAX_NUM_OBJECTS * 3]; +#ifdef CONF_DISTATT + float distAtt[3]; +#endif } IVAS_RENDER_CONFIG_DATA, *IVAS_RENDER_CONFIG_HANDLE; diff --git a/lib_com/options.h b/lib_com/options.h index 43cb02520e..e73218670b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -160,6 +160,7 @@ #define FIX_1053_REVERB_RECONFIGURATION /* Philips: issue 1053: fix for dynamic switching of acoustic environment */ +#define CONF_DISTATT /* Eri: Make distance attenuation configurable */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 174aac81da..76e2cf36c9 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 } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 71f89ea508..92e2979447 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -2292,6 +2292,9 @@ ivas_error IVAS_DEC_FeedRenderConfig( #endif mvr2r( renderConfig.directivity, hRenderConfig->directivity, 3 * MAX_NUM_OBJECTS ); +#ifdef CONF_DISTATT + mvr2r( renderConfig.distAtt, hRenderConfig->distAtt, 3 ); +#endif #ifdef SPLIT_REND_WITH_HEAD_ROT hRenderConfig->split_rend_config = renderConfig.split_rend_config; diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index f6a14f66f0..522ab52167 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; @@ -224,11 +230,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 +665,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,9 +697,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 3f580df504..484dd4bf3f 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->RefDist ), 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->RefDist ), 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 0434031c81..7f557c7f19 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_util/render_config_reader.c b/lib_util/render_config_reader.c index 981f261420..e2dd368981 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 }; @@ -996,6 +999,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,6 +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 */ @@ -1245,6 +1322,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 * IVAS_MAX_NUM_OBJECTS] = max( 0.0f, min( 360.0f, hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS] ) ); + hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS + 1] = max( 0.0f, min( 360.0f, hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS + 1] ) ); + hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS + 2] = max( 0.0f, min( 1.0f, hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS + 2] ) ); + } +#endif } @@ -1287,6 +1380,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 +1902,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 ); @@ -2653,6 +2779,54 @@ 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; @@ -2909,6 +3083,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 445ced79ab..4fb9280ff1 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 */ diff --git a/scripts/reverb/text_to_binary_payload.py b/scripts/reverb/text_to_binary_payload.py index 7eff404a7a..4f958c7512 100644 --- a/scripts/reverb/text_to_binary_payload.py +++ b/scripts/reverb/text_to_binary_payload.py @@ -84,6 +84,7 @@ def parse_reverb_text_configuration_and_generate_binary_payload(file): "acousticEnvironment", "directivitySetting", "directivityPattern", + "distanceAttenuation", ] } for section_name in config.sections(): @@ -99,6 +100,7 @@ def parse_reverb_text_configuration_and_generate_binary_payload(file): assert section_name in [ "roomAcoustics", "directivitySetting", + "distanceAttenuation", ], f"unknown section name: {section_name}" sections[section_name] = config[section_name] @@ -229,10 +231,19 @@ def parse_reverb_text_configuration_and_generate_binary_payload(file): + get_angle_code(dir_values[1]) # Directivity outer angle + get_outer_attenuation_code(dir_values[2]) ) # Directivity outer attenuation + + # parse distance attenuation + hasDistanceAttenuation = len(sections["distanceAttenuation"]) > 0 + data += get_bool_code(hasDistanceAttenuation) + if hasDistanceAttenuation: + data += bitarray( + get_maxdist_code(eval_option(sections["distanceAttenuation"]["maxDist"])) # Distance attenuation Max Distance + + get_refdist_code(eval_option(sections["distanceAttenuation"]["refDist"])) # Distance attenuation Ref Distance + + get_rolloff_code(eval_option(sections["distanceAttenuation"]["rolloffFactor"])) # Distance attenuation Rolloff Factor + ) # generate binary file data.tofile(open(file.split(".")[0] + ".dat", "wb")) - if __name__ == "__main__": import argparse -- GitLab From 0b49441ec3d5e2302c17ba884aad58749aaa499a Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 30 Apr 2024 08:12:31 +0200 Subject: [PATCH 2/7] Fix missing st_ivas->hRenderConfig->distAtt --- lib_dec/ivas_objectRenderer_internal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 76e2cf36c9..a4fac70892 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -276,6 +276,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 ) -- GitLab From 5e266a1e82ca9f7bbdaeeb83ac428eaa29595dd9 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 1 May 2024 17:56:39 +0200 Subject: [PATCH 3/7] Fix in CONF_DISTATT --- lib_rend/ivas_render_config.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index e9c9fa749a..45a5e707e8 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 #ifdef SPLIT_REND_WITH_HEAD_ROT ( *hRenderConfig )->split_rend_config.splitRendBitRate = SPLIT_REND_768k; ( *hRenderConfig )->split_rend_config.dof = 3; -- GitLab From 2237d559f913f58b25343eef1a323c7bc639db03 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 2 May 2024 08:34:39 +0200 Subject: [PATCH 4/7] Fixes in DistGain calculation and init for MC --- lib_rend/ivas_objectRenderer.c | 13 +++++++++++++ lib_rend/ivas_objectRenderer_sources.c | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib_rend/ivas_objectRenderer.c b/lib_rend/ivas_objectRenderer.c index 522ab52167..4aac09eafa 100644 --- a/lib_rend/ivas_objectRenderer.c +++ b/lib_rend/ivas_objectRenderer.c @@ -190,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; @@ -209,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 } } diff --git a/lib_rend/ivas_objectRenderer_sources.c b/lib_rend/ivas_objectRenderer_sources.c index 484dd4bf3f..a0f489f35d 100644 --- a/lib_rend/ivas_objectRenderer_sources.c +++ b/lib_rend/ivas_objectRenderer_sources.c @@ -609,7 +609,7 @@ static float TDREND_SRC_SPATIAL_GetDistGain( { case TDREND_DIST_ATTEN_MODEL_INV_DIST: #ifdef CONF_DISTATT - DistGain = powf( DistAtten_p->RefDist / ( Dist2 - DistAtten_p->RefDist ), DistAtten_p->RollOffFactor ); + 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 @@ -626,7 +626,7 @@ static float TDREND_SRC_SPATIAL_GetDistGain( Dist2 = DistAtten_p->MaxDist; } #ifdef CONF_DISTATT - DistGain = powf( DistAtten_p->RefDist / ( Dist2 - DistAtten_p->RefDist ), DistAtten_p->RollOffFactor ); + 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 -- GitLab From 5f901e6325fe7df9cbad0bcb0fdaf7e38e4d0c5e Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 2 May 2024 08:36:21 +0200 Subject: [PATCH 5/7] Clang format --- lib_rend/ivas_render_config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_rend/ivas_render_config.c b/lib_rend/ivas_render_config.c index 45a5e707e8..0a8d7c1d72 100644 --- a/lib_rend/ivas_render_config.c +++ b/lib_rend/ivas_render_config.c @@ -132,9 +132,9 @@ ivas_error ivas_render_config_init_from_rom( ( *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 */ + ( *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 #ifdef SPLIT_REND_WITH_HEAD_ROT ( *hRenderConfig )->split_rend_config.splitRendBitRate = SPLIT_REND_768k; -- GitLab From 316ee1e76b2b6111df3d1c19fc721efdcd4c4999 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 2 May 2024 10:56:32 +0200 Subject: [PATCH 6/7] Correction in directivity value check --- lib_util/render_config_reader.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index e2dd368981..25e5f76d3f 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -1333,9 +1333,9 @@ ivas_error RenderConfigReader_checkValues( /* Verify range of directivity patterns */ for ( i = 0; i < IVAS_MAX_NUM_OBJECTS; i++ ) { - hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS] = max( 0.0f, min( 360.0f, hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS] ) ); - hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS + 1] = max( 0.0f, min( 360.0f, hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS + 1] ) ); - hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS + 2] = max( 0.0f, min( 1.0f, hRenderConfig->directivity[i * IVAS_MAX_NUM_OBJECTS + 2] ) ); + 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 } -- GitLab From 71bde365b3cc0060371abd4c5f23f916264ae5df Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 8 May 2024 14:54:52 +0200 Subject: [PATCH 7/7] Add missing update to generate_acoustic_environments_metadata.py for generating binary format --- .../reverb/generate_acoustic_environments_metadata.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/reverb/generate_acoustic_environments_metadata.py b/scripts/reverb/generate_acoustic_environments_metadata.py index 58017d983b..cba887724c 100644 --- a/scripts/reverb/generate_acoustic_environments_metadata.py +++ b/scripts/reverb/generate_acoustic_environments_metadata.py @@ -731,6 +731,17 @@ def get_angle_code(angle): assert 0 <= angle <= 360 return usquant(angle, 0, 20, 19) +def get_refdist_code(dist): + assert 0 <= dist + return usquant(dist, 0.1, 0.1, 64) + +def get_maxdist_code(dist): + assert 0 <= dist + return usquant(dist, 1, 1, 64) + +def get_rolloff_code(rollof): + assert 0 <= rollof + return usquant(rollof, 0, 0.1, 41) def get_outer_attenuation_code(att): assert 0 <= att <= 1 -- GitLab